Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add widgets into a QTabWidget

Can I add some widgets like QLabel and QPushButton into a QTabWidget?

Actually, I want to do something like this: enter image description here

I'm using C++ and Qt.

Thanks

like image 690
KelvinS Avatar asked Jun 06 '16 03:06

KelvinS


People also ask

How do I use tab widget in Qt?

The normal way to use QTabWidget is to do the following: Create a QTabWidget. Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them. Insert child widgets into the page widget, using layouts to position them as normal.

How do I add a tab in PyQt?

PyQt tabs example To add a tab to a QTabWidget , call the method . addTab() . label1 = QLabel("Widget in Tab 1.") label2 = QLabel("Widget in Tab 2.")

What is QVBoxLayout?

QVBoxLayout organizes your widgets vertically in a window. Instead of organizing all the widgets yourself (specifying the geographic location), you can let PyQt take care of it. Every new widget you add with . addWidget() , is added vertically. Basically you get a vertical list of your widgets.


1 Answers

It's possible, just use QTabWidget::setCornerWidget.

Quick example:

        QWidget* pTabCornerWidget = new QWidget(this);

        QLabel* pLabelTime = new QLabel(pTabCornerWidget);
        pLabelTime->setText("10:22:20");

        QPushButton* pButton = new QPushButton(pTabCornerWidget);
        pButton->setText("?");
        pButton->setMaximumSize(QSize(25, 25));

        QHBoxLayout* pHLayout = new QHBoxLayout(pTabCornerWidget);
        pHLayout->addWidget(pLabelTime);
        pHLayout->addWidget(pButton);

        mUI.tabWidget->setCornerWidget(pTabCornerWidget, Qt::TopRightCorner);
like image 179
Gediminas Avatar answered Sep 25 '22 21:09

Gediminas