Results 1 to 7 of 7

Thread: repaint a cell or row in QTableWidget

  1. #1
    Join Date
    Feb 2006
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default repaint a cell or row in QTableWidget

    Hello everyone,

    I have a QTableWidget (3 columns,rows are added by a loop).
    I would like to know if it is possible to repaint a cell,or a row, without repainting the whole table.
    I have read that method repaint() can't be used in a QTableWidgetItem.

    If anyone has an idea please let me know.

    Thanks

  2. #2
    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: repaint a cell or row in QTableWidget

    Use update() with parameters set to your item's rectangle (visualItemRect());

    BTW. Try to avoid using repaint() if possible.

  3. #3
    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: repaint a cell or row in QTableWidget

    First, get the rectangle occupied an item by QTableWidget::visualItemRect().
    Then you can update this specific area in your table widget by QWidget::update().

  4. #4
    Join Date
    Feb 2006
    Posts
    5
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: repaint a cell or row in QTableWidget

    thank u all for your answers.
    my pb with method update is :
    "This function does not cause an immediate repaint; instead it schedules a paint event for processing when Qt returns to the main event loop."

    in fact i want immediate repainting.
    when a new row is added, it is highlighted directly (background in red, then after white)

    thanks

  5. #5
    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: repaint a cell or row in QTableWidget

    Hmm, then try processing all pending events after updating:

    void QCoreApplication:rocessEvents ( QEventLoop::ProcessEventsFlags flags = QEventLoop::AllEvents ) [static]

  6. #6
    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: repaint a cell or row in QTableWidget

    Quote Originally Posted by alphaqt
    in fact i want immediate repainting.
    when a new row is added, it is highlighted directly (background in red, then after white)
    It will be immediate -- for your eyes. In reality it'll be a few miliseconds later, but I'm sure you won't notice The point is that each repaint() is executed immediately and two or more update() calls can be "merged", resulting in much more efficient painting. That's why it's better to use update() (and probably why repaint() is protected).

  7. #7
    Join Date
    Jun 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: repaint a cell or row in QTableWidget

    Quote Originally Posted by wysota View Post
    Use update() with parameters set to your item's rectangle (visualItemRect());

    BTW. Try to avoid using repaint() if possible.
    can u give a simple snippet of code showing how to use the update() and visualitemrect() functions. I am facing a similar problem too. Give a snippet of code wherein i have to update a column(every element in the column) in the table with time.

    Thanks!!

Similar Threads

  1. Replies: 5
    Last Post: 26th October 2014, 12:56
  2. Replies: 1
    Last Post: 2nd December 2008, 18:33
  3. Problems with QString
    By cyberboy in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2008, 08:18
  4. Replies: 0
    Last Post: 2nd May 2008, 07:57
  5. Word wrapping in a QTableWidget cell
    By jcooperddtd in forum Qt Programming
    Replies: 3
    Last Post: 1st May 2007, 03:57

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.