QDockWidget Draggable Tabs

前端 未结 7 1791
执念已碎
执念已碎 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:57

    Edited:

    Please do not use this method. It introduces problems rather than soloves them.


    Maybe you can try this wierd way, that is move the QWidget in the dock widget area to the title bar.

    I modify the demo in folder

    C:\Qt\Qt5.12.9\Examples\Qt-5.12.9\widgets\mainwindows\dockwidgets

    to show how it works:

    In "void MainWindow::createDockWindows()"

    QDockWidget *dock = new QDockWidget(tr("Customers"), this);
    dock->setAllowedAreas(Qt::LeftDockWidgetArea | Qt::RightDockWidgetArea);
    
    //make a panel to hold your widgets
    QWidget *p = new QWidget(dock);
    QVBoxLayout *l = new QVBoxLayout(p);
    p->setLayout(l);
    customerList = new QListWidget(p);
    l->addWidget(customerList);
    
    customerList->addItems(QStringList()
            << "John Doe, Harmony Enterprises, 12 Lakeside, Ambleton"
            << "Jane Doe, Memorabilia, 23 Watersedge, Beaton"
            << "Tammy Shea, Tiblanka, 38 Sea Views, Carlton"
            << "Tim Sheen, Caraba Gifts, 48 Ocean Way, Deal"
            << "Sol Harvey, Chicos Coffee, 53 New Springs, Eccleston"
            << "Sally Hobart, Tiroli Tea, 67 Long River, Fedula");
    
    dock->setWidget(new QWidget());//hide the real dock area
    dock->setTitleBarWidget(p); //use the titlebar erea to show the content
    

    The demo:

    Drag the edge of the panel to move, actually you can drag the empty area (no child widget area). The widget on this panel still functional properly.

    0 讨论(0)
提交回复
热议问题