Results 1 to 12 of 12

Thread: cell not updating in table Widget afterclicking on it

  1. #1
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default cell not updating in table Widget afterclicking on it

    greetings qt users and developers,

    I had created a table Widget. Whenever i click on any cell of table, it is highlighted with certain color at background. Now if i click at some other cell previous celll will show data but printed with some offset in pixels resulting in blurred or not-refreshed view.

    quickNitin

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: cell not updating in table Widget afterclicking on it

    How do you set/unset the highlighting? The view should update itself correctly if you simply use QTableWidgetItem::setBackgroundColor() or similar.

    But, if you are drawing a custom highlight, the problem might be for example that the model doesn't really change anyhow and the view doesn't know to update itself. I did some custom highlight effect back then and used
    Qt Code:
    1. setDirtyRegion(visualItemRect(item));
    To copy to clipboard, switch view to plain text mode 
    to manually schedule item's area to be updated. Doesn't look or feel very elegant but it works.

    From docs:
    void QAbstractItemView::setDirtyRegion ( const QRegion & region ) [protected]
    Marks the given region as dirty and schedules it to be updated. You only need to call this function if you are implementing your own view subclass.
    This function was introduced in Qt 4.1.
    J-P Nurmi

  3. #3
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: cell not updating in table Widget afterclicking on it

    Quote Originally Posted by jpn
    How do you set/unset the highlighting? The view should update itself correctly if you simply use QTableWidgetItem::setBackgroundColor() or similar.
    i had done this only. No custom highlight. only setting of background color. So i was thinking i had put anything for refreshing?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: cell not updating in table Widget afterclicking on it

    Can we see the code?

  5. #5
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Angry Re: cell not updating in table Widget afterclicking on it

    here is snap of code which is responsible for posting data to table widget elements
    Qt Code:
    1. QLabel *lb;
    2. .
    3. .
    4. .
    5. lb=dynamic_cast<QLabel*>(tw.cellWidget(row,col));
    6. lb->setText(QString::number(y));
    7. lb->setBackGroundColor(Qt::Blue);
    8. col++;
    9. lb=dynamic_cast<QLabel*>(tw.cellWidget(row,col));
    10. lb->setText(QString::number(x));
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: cell not updating in table Widget afterclicking on it

    You can either set the background color directly for the item: QTableWidgetItem::setBackgroundColor() (and not for the label),
    or you can make the label to fill it's background: QWidget::setAutoFillBackground() (child widgets are transparent by default since 4.1).

    PS. QWidget::setBackgroundColor() is some obsolete Qt3 support member and advised against using.
    J-P Nurmi

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: cell not updating in table Widget afterclicking on it

    Do you need those labels at all?

  8. #8
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: cell not updating in table Widget afterclicking on it

    i am using Qlable to set text on cell of table. As u have given hint there may be other way also i weill look for that also.

  9. #9
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: cell not updating in table Widget afterclicking on it

    It is sometimes useful to take a glance at the docs before implementation.. QTableWidgetItem::setText().
    J-P Nurmi

  10. #10
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: cell not updating in table Widget afterclicking on it

    since at time of creation of tableWidget i used used QLable as cell item , so that followed . I am updating to QTableWidgetItem

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: cell not updating in table Widget afterclicking on it

    Why did you do that in the first place?

  12. #12
    Join Date
    Apr 2006
    Posts
    122
    Thanks
    18
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: cell not updating in table Widget afterclicking on it

    just because while going through doc i came through one such example. ALso my requirment was to display text only in widget. So i followed it. No other reason.

Similar Threads

  1. Center a widget in a cell on a QTableWidget
    By roleroz in forum Qt Programming
    Replies: 16
    Last Post: 5th March 2009, 14:47
  2. Table cell merge/join
    By larry104 in forum Qt Programming
    Replies: 6
    Last Post: 16th June 2006, 22:35
  3. Dynamic updates to a table widget
    By guiGuy in forum Qt Programming
    Replies: 6
    Last Post: 1st June 2006, 20:24
  4. Highlighting the border of cell in Table
    By ankurjain in forum Qt Programming
    Replies: 8
    Last Post: 21st March 2006, 08:20

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.