QDockWidget Draggable Tabs

前端 未结 7 1793
执念已碎
执念已碎 2020-12-31 00:59

I am using QDockWidgets and placing two of them on the left side of my application so that tabs can be used to select between them. However, Qt\'s default behavior for this

7条回答
  •  轮回少年
    2020-12-31 01:48

    As far as I can see from QDockWidget::mousePressEvent implementation in src/gui/widgets/qdockwidget.cpp dragging the dockwidgets using tabs is NOT possible:

    QDockWidgetLayout *dwLayout
        = qobject_cast(layout);
    
    if (!dwLayout->nativeWindowDeco()) {
        QRect titleArea = dwLayout->titleArea();
    
        if (event->button() != Qt::LeftButton ||
            !titleArea.contains(event->pos()) ||
            // check if the tool window is movable... do nothing if it
            // is not (but allow moving if the window is floating)
            (!hasFeature(this, QDockWidget::DockWidgetMovable) && !q->isFloating()) ||
            qobject_cast(parent) == 0 ||
            isAnimating() || state != 0) {
            return false;
        }
    
        initDrag(event->pos(), false);
        ....
    

    As you can see from the implementation one of the things that the QDockWidget checks before allowing undocking is whether the mouse press event has come from title bar or not.

提交回复
热议问题