Weird behaviour with custom widget if used in a DockWidget



  • I created a widget that is based on QListView and uses QStandardItem to display thumbnails for each image file that it finds on a user defined directory. See this image for more details.

    The widget works fine when on its own, but as soon as I tried using it with an existing project by including it as a dockable widget it started behaving rather oddly.

    If one tries to use the scrollbar on the left Qt will constantly complain throwing

    QNSView mouseDragged: Internal mouse button tracking invalid (missing Qt::LeftButton)
    

    for as long and you try to scroll.
    Not only that but sometimes even hovering somewhere in the scrollbar will behave as if clicking on that position and the scroll will try to move towards the mouse.

    Even more weird is the fact that if I click and drag on the side of the dock that separates it with the rest of the app then nothing happens, my thumbnails viewer won't resize. But if I hold the mouse over that area without clicking and slowly move it, then for a little bit the separator will follow the mouse and the dock will resize.

    I think the whole issue is that for some reason the mouse release event gets lost. Or something similar.

    This is a bit of a weird issue I think, thus I doubt many people have encountered it.
    If you have any ideas though please do say so.

    Thanks.

    EDIT:
    If instead of using a dock widget I simply show the thumbnail viewer on a separate window none of the above problems exist.

    EDIT 2:
    If I keep at it and constantly drag the scrollbar the app will eventually crush reporting

    QWidget::repaint: Recursive repaint detected
    QWidget::paintEngine: Should no longer be called
    QPainter::begin: Paint device returned engine == 0, type: 1
    

    Here is the topmost part of the crush report:

    Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
    0   QtGui                         	0x0000000100936229 QPaintEngine::syncState() + 9
    1   QtWidgets                     	0x000000010012170d (anonymous namespace)::QMacCGContext::QMacCGContext(QPainter*) + 45
    2   QtWidgets                     	0x0000000100126f67 QMacStyle::drawPrimitive(QStyle::PrimitiveElement, QStyleOption const*, QPainter*, QWidget const*) const + 119
    3   QtWidgets                     	0x00000001001e1eea QStyleSheetStyle::drawPrimitive(QStyle::PrimitiveElement, QStyleOption const*, QPainter*, QWidget const*) const + 3866
    4   QtWidgets                     	0x00000001002db90e QAbstractScrollArea::event(QEvent*) + 1726
    5   QtWidgets                     	0x000000010035f614 QAbstractItemView::event(QEvent*) + 500
    6   QtWidgets                     	0x0000000100380c19 QListView::event(QEvent*) + 9
    7   QtWidgets                     	0x00000001001452dc QApplicationPrivate::notify_helper(QObject*, QEvent*) + 300
    8   QtWidgets                     	0x0000000100147d9b QApplication::notify(QObject*, QEvent*) + 6187
    9   QtCore                        	0x0000000100ec6a52 QCoreApplication::notifyInternal(QObject*, QEvent*) + 114
    10  QtWidgets                     	0x0000000100178325 QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) + 2997
    11  QtWidgets                     	0x0000000100178a7a QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) + 1146
    12  QtWidgets                     	0x00000001001785c6 QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) + 3670
    13  QtWidgets                     	0x0000000100178a7a QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) + 1146
    14  QtWidgets                     	0x0000000100178909 QWidgetPrivate::paintSiblingsRecursive(QPaintDevice*, QList<QObject*> const&, int, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) + 777
    15  QtWidgets                     	0x00000001001785c6 QWidgetPrivate::drawWidget(QPaintDevice*, QRegion const&, QPoint const&, int, QPainter*, QWidgetBackingStore*) + 3670
    

    EDIT 3:
    After testing it on my windows machine too, can confirm that this is only a Mac issue.


  • Lifetime Qt Champion

    Hi,

    You should take a look at the bug report system to see if it's something known. If not please consider opening a new report providing a minimal compilable example that reproduces this behavior.



  • Hi,
    There is a bug regarding the

    QNSView mouseDragged: Internal mouse button tracking invalid (missing Qt::LeftButton)

    message here and a long time. I will have to do more tests and make sure that this is a different thing.



  • I did figure out another thing. It seems that the problem occurs only when the dock widget has focus.
    If the focus is on any other part of the app then the dock widget behaves fine.

    I will try to create a compilable example that reproduces this behaviour.

    EDIT:

    • Seems that setResizeMode(QListView::Adjust); does not play well when your listView is inside a dock widget.

    • Make suer you leave a margin between your widgets' content and the sides of the dock widget in order to avoid the QNSView mouseDragged: Internal mouse button tracking invalid (missing Qt::LeftButton) message when trying to resize with the mouse.

    • For the scrollbar issue I managed to better identify the cause. It seems that if you are careful enough so as your mouse pointer never gets outside the scrollbar then you are fine. As soon as you leave the scrollbar a little bit on the left or on the right the you get the QNSView mouseDragged: Internal mouse button tracking invalid (missing Qt::LeftButton) and qt start acting crazy. Mostly I think because it looses the mouseReleased or mousePressed events. Thus we can simply do setFocusPolicy(Qt::NoFocus); to overcome it.


  • Lifetime Qt Champion

    It something you should bring on thebug report system IIRC there were already some reports about these tracking errors



  • I know, and I want to, but I don't think I can because I can't create a good compilable example that reproduces the error. If you simply create a dockWidget that has a listView and you try to scroll it is fine. Even though I tried to configure it the same way.
    I am not sure what exactly in my app triggered this bug.


Log in to reply
 

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