c++ - Qt 设置 TabBar

标签 c++ qt

我正在使用 Qt Framework 制作应用程序,但遇到了一个问题: 我这样定义一个 TabWidget

QTabWidget *armaTab = new QTabWidget();
armaTab->setContentsMargins(0, 0, 0, 0);
armaTab->setTabPosition(QTabWidget::North);
armaTab->setObjectName(QString::fromUtf8("armaTab"));

然后我尝试像这样添加一个 QTabBar:

QTabBar *tabBar = new QTabBar();
tabBar->setContentsMargins(0, 0, 0, 0);
tabBar->setFont(*font);
tabBar->setObjectName(QString::fromUtf8("armaTabBar"));
armaTab->setTabBar(tabBar);

我得到这个错误:

error: 'void QTabWidget::setTabBar(QTabBar*)' is protected
error: within this context

谁能解释一下我的错误在哪里?

最佳答案

这只是意味着您必须注意访问组件:来自文档:

void QTabWidget::setTabBar ( QTabBar * tb ) [protected]

Replaces the dialog's QTabBar heading with the tab bar tb. Note that this must be called before any tabs have been added, or the behavior is undefined.

我认为您可以简单地将 QTabWidget 子类化以访问 protected 成员...

关于c++ - Qt 设置 TabBar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18644448/

相关文章:

c++ - 这是什么语法 : "ACGT"[(int)qrand() % 4]

c++ - 将一个信号连接到同一线程的两个插槽

c++ - 程序在错误的位置查找 libstdc++.so.6,似乎忽略了 LD_LIBRARY_PATH

c++ - 使用继承时是否需要 "#include"子类父类的头文件。 C++

C++ 全局函数和 OOP?

c++ - QT串口读取

Qt-无法保存jpeg文件

c++ - 访问 QMap 的 QMap<QString, QPair<int, int>>

c++ - 二维 vector 初始化

java - 何时使用 CallNonvirtualObjectMethod 及其相关方法?