Important: Please read the Qt Code of Conduct -

Wrong resize value for items inside a QListWidget with QSplitter

  • I have a QListWidget inside a QTabWidget and I resize that section often with an horizontal QSplitter. Inside the QListWidget I use setItemWidget to set complex widgets with buttons on the items.

    The problem is: when moving QSplitter, it seems that the position used to resize the widgets is always one tick earlier. If I move slow, I can see all the buttons, but if I resize fast the splitter, I can even lose 1/3 of my widgets, meaning that the widgets are wider than the QListWidget and are cut behind. And it doesn't refresh. The QListWidget itself resize properly, I can always see its border.

    Even with .setOpaqueResize(False), I can pause for a second, then release, and the widgets are still not sized properly. It's like it doesn't use the mouse position on button release.

    Also, when I resize, sometimes I can see artefacts, like if the sizeHint is not smooth and making the draw forth and back. I have subclassed QListWidget but I didn't override any of its methods. I have the same issue with another QListWidget, using different widgets inside the list.

  • @BrianK please provide a minimal and verifiable example.

  • I just tried to provide a reproducible example but failed to do so.

    I created a fresh QWidget with a QSplitter seperating 3 widget sections, then I used my subclassed QListWidget along with my complex widgets.

    I used the same methods to populate the list. No bug. That means it may have to do with something else.

    Now I used .hide() on the content inside the other QSplitter sections and I removed all style sheets. I still have the bug in my main app.

    This is so strange.

  • OK, I found a partial fix:


    I use QtDesigner to create my layout, then create a class with that code. This line was causing trouble. Apparently, when it is set to ScrollBarAlwaysOff, the QListWidget only refresh on mouse move and is often one tick behind.

    What I still haven't figured out is why my widgets, and even my QLineEdit on top of the QListWidget (in a vertical layout), have their right side moving and drawing on the far right when resizing with QSplitter. Its flickering forth and back on the right side, when it should never move at all. The handle is on the left and on the right its the end. It should be static.

  • OK, so, the flickering comes from the central widget in the splitter being a QVTKRenderWindowInteractor (VTK renderer).

  • QVTKRenderWindowInteractor can inherit from QWidget or QGLWidget. I tried both.

    I have hidden the QVTKRenderWindowInteractor and tested to make sure that it wasn't resizing. That way I could test if it was caused by resize / sizeHint subclassing. The app didn't go there.

    It seems that even when not resizing, the having QVTKRenderWindowInteractor as a child or inside QSplitter will cause flickering to widgets in other sections.

Log in to reply