Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Force repaint for a QTreeWidgetItem
Forum Update on Monday, May 27th 2025

Force repaint for a QTreeWidgetItem

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 2.8k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    herb77
    wrote on last edited by
    #1

    I have written my own ItemDelegate to do some search highlighting in a QTreeWidget. When I set the string to be highlighted in the delegate, all the QTreeWidgetItems in a QTreeView shall be repainted (and highlighted if they match).
    But when I call repaint() or update() on the QTreeWidget nothing happens. It is updated as soon as the mouse hovers it, but not before. I am in the UI thread, so this can not be the problem.
    As a workaround, I have the following code:

    for( int i = 0; i < treeWidget->topLevelItemCount(); ++i )
    {
    QTreeWidgetItem *item = treeWidget->topLevelItem( i );
    QString text = item->text(0);
    item->setText(0, "");
    item->setText(0, text);
    }

    This causes a dataChanged() in the model and the items are repainted.
    It seems to me that the TreeWidget is double buffered or something in like that and it only paints the existing buffer if nothing changed (i.e. a dataChanged() event from the model or scrolling or something like this).
    Is there any better way to force a 'real' repaint?

    Thanks a lot!

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved