×

Discussion Board

Results 1 to 1 of 1
  1. #1
    Registered User
    Join Date
    Nov 2010
    Posts
    2

    Some cells in QtableView are not repainted automatically after a clicking on a cell

    Hello,

    I'm using a QTableView in the implementation of an interactive board game. Images are to be displayed in the cells of the table. I'm using a QStyledItemDelegate with a paint function to draw the images inside the table cells.

    As the images should be displayed only in certain cells of the table and updated when a user clicks on a table cell, a double int array is used which is of the same dimensions as the table. Depending on the values of the array, the painter should draw images in specific cells of the table. Initially there are only 4 images inside 4 cells of the table and as the user clicks on a cell in the table, the array is updated which should consequently mean that whats drawn and displayed inside the cells of the table should be changed.

    Normally the user clicks on an empty (white) cell which is updated successfully and the specific image is shown in the cell. However, if there are other cells which contain an image and should be updated, the update is not shown, although the double int array is updated. I also saw a weird thing, that is when I click on the cells in which their display should have been updated, the update happens. This of-course occurs regardless of how I update when someone clicks on a cell. Also, highlighting a cell after the user has clicked on it does not seem to work; I still see white background inside the cell's area.

    Does the delegate runs continuously in a thread and the painter function is called with the index of each cell in the table? I do not get how an update on a cell containing an Image does not update automatically although the painter should have redrawn the cell's area and it occurs only after the a click on the cell has been made. Or its cus a new painter is called to the painter's function each time?!

    Well, here is my implementation of the painter's function of the delegate:

    Code:
      void Sphere::paint(QPainter *painter, const QStyleOptionViewItem &option,
                              const QModelIndex &index) const
      {
    	 painter->save();
         if(tb1[index.row()][index.column()] == 1)
    	 {
    		 QImage Q1("Red Sphere.jpg");
    
    	 QRectF source(0.0, 0.0, 72.0, 70.0);
    
    	 if (option.state & QStyle::State_Selected)
                 painter->fillRect(option.rect, option.palette.highlight());
    
    	 painter->drawImage(option.rect, Q1, source);
    
    	 }
    	 else if(tb1[index.row()][index.column()] == 2)
    	 {
    		 QImage Q1("Blue Sphere.jpg");
    
    	 QRectF source(0.0, 0.0, 72.0, 70.0);
    
    	 if (option.state & QStyle::State_Selected)
                 painter->fillRect(option.rect, option.palette.highlight());
    
    	 painter->drawImage(option.rect, Q1, source);
    
    	 }
    	 else 
    	 {
    		 QStandardItemModel *model = (QStandardItemModel*) index.model();
    		 if(!model->item(index.row(), index.column())->isEnabled())
    			 QStyledItemDelegate::paint(painter, option, index);
    		 else
    		 {
    		 painter->fillRect(option.rect, Qt::white);
    		 }
    	 }
         painter->restore();
      }
    I also tried to use QAbstractItemView::update(const QModelIndex & index) for all items (cells) that should be updated by:

    Code:
     QPoint Q(row, col);
     ui.tableView->update(ui.tableView->indexAt(Q));
    But its still not working. I can give you any more info if u needed to solve my problem. Thanks in advance.

    EDIT: I got it. I called update(const QModelIndex & index) in the painter's function of the delegate at the beginning (first line) and it worked. Not sure if this was the best way to do it but it worked. Thanks guys for trying to help. I'm sure none of you have found the answer to my problem . Else I would have seen replies wouldn't I?
    Last edited by Mezzo; 2011-06-10 at 20:51.

Similar Threads

  1. Replies: 1
    Last Post: 2010-08-24, 21:51
  2. How to stop a task automatically after some time?
    By suiying0792 in forum Symbian
    Replies: 3
    Last Post: 2009-08-26, 06:17
  3. Grid Cells are not visible
    By sarayu in forum Symbian
    Replies: 1
    Last Post: 2008-03-07, 07:59
  4. Grid Cell formatting are not getting effected on 6600
    By xxyyzz in forum Symbian User Interface
    Replies: 0
    Last Post: 2004-11-16, 11:35

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×