QListWidgetItem setText() does not trigger repaint



  • I'm using creator 3.2.1 and qt 5.3.2. I have a class that inherits QListWidget. It has 2 additional functions that are called by a network thread when something comes in over the network. One of the functions basically takes the new data and does an addItem(text) call to add an item to the list. The other function modifies and existing item by finding the item in the list and calling setText(text) on the item.

    The addItem(text) works as I want, I immediately see the new item show up in the list. The modify function is not working the way I want. I only see the modified value if I move my cursor over the QListWidget or move it away (focus changes). If I leave the cursor over the QListWidget, I do not see the updates, only if I move it into or out of the list area.

    A cheesy semi-workaround is that after calling setText(text) on the item, I can call setFocus() and then clearFocus() on the QListWidget class. This allows me to see the changes as they come in, but only if the application is in focus, whereas the addItem(text) shows whether or not the application is in front.

    I tried using update() after the setText(text), but it had no effect. I don't want to call repaint() directly as typically many things will change at the same time and I don't want to kill all the optimization.

    Is there a better way to trigger a repaint?



  • Nevermind. This thread can be deleted (I couldn't figure out how if it allows me to).

    I tried to reproduce the problem with a simple GUI that added to the list every 10 seconds and modified the first entry every second using a QTimer. Did not have the problem here, so I looked at the threaded part of my more complicated GUI.

    Not sure exactly what was wrong, but it may have had something to do with the network work being done in a separate thread. I was getting this error during runtime:
    QObject::connect: Cannot queue arguments of type 'QVector<int>'
    (Make sure 'QVector<int>' is registered using qRegisterMetaType().)

    After searching on that error, I ended up changing the callbacks from the network thread to pass const pointers instead of just pointers. I also added a line to the main function qRegisterMetaType<QVector<int> >().

    At this point, the runtime errors went away and so did the issue with the list not updating unless focus changed. Not really sure why they're related, but it appears one of those 2 changes corrected it.


  • Lifetime Qt Champion

    Hi and welcome to devnet,

    The registration part means that the connection where you used QVector<int> as parameter were not working.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.