How can I add a “new tab” button next to the tabs of a QMdiArea in tabbed view mode?

后端 未结 5 1195
天命终不由人
天命终不由人 2020-12-05 14:46

I\'d like to have a \"new tab\" button much like Chrome or Firefox has for my QMdiArea.

I can make a button or menu item somewhere that adds a new subdo

5条回答
  •  不知归路
    2020-12-05 15:10

    I know that question is outdated, but some time ago I was looking for ready-to-use implementation of feature you requested. I digged a bit and implement this for Qt 5 -- take a look at repo.

    Main idea is to do:

    // Create button what must be placed in tabs row
    QToolButton *tb = new QToolButton();
    tb->setText("+");
    // Add empty, not enabled tab to tabWidget
    tabWidget->addTab(new QLabel("Add tabs by pressing \"+\""), QString());
    tabWidget->setTabEnabled(0, false);
    // Add tab button to current tab. Button will be enabled, but tab -- not
    tabWidget->tabBar()->setTabButton(0, QTabBar::RightSide, tb);
    

提交回复
热议问题