我正在使用 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/