c++ - 将小部件添加到 QTabWidget

标签 c++ qt qlabel qpushbutton qtabwidget

我可以在 QTabWidget 中添加一些小部件,例如 QLabelQPushButton 吗?

实际上,我想做这样的事情: enter image description here

我正在使用 C++ 和 Qt。

谢谢

最佳答案

有可能,就用QTabWidget::setCornerWidget .

简单示例:

        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);

关于c++ - 将小部件添加到 QTabWidget,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37649177/

相关文章:

.net - 确定何时在(非托管)C++ 中加载 .NET

c++ - 使用析构函数时双重释放或损坏

qt - 如何定义qml GroupBox标题样式

c++ - Qt Creator 找不到库文件

python - C++ 中的递归生成器

C++ 将一个参数默认为另一个参数

c++ - gluPickMatrix - 出了点问题,一个对象总是在现场

c++ - Qt QLabel HTML 字体大小严重失败

c++ - 合并多个 QPixmaps 的问题

c++ - 如何使多行 QLabel 省略最后一行,受最大高度限制,但如果文本未填充到最大高度也会缩小?