本文整理汇总了C++中QTabBar::documentMode方法的典型用法代码示例。如果您正苦于以下问题:C++ QTabBar::documentMode方法的具体用法?C++ QTabBar::documentMode怎么用?C++ QTabBar::documentMode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTabBar
的用法示例。
在下文中一共展示了QTabBar::documentMode方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: main
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
auto *proxyStyle = new TabBarProxyStyle;
app.setStyle(proxyStyle);
QWidget widget;
QStackedWidget stackedWidget;
QTabBar tabBar;
tabBar.setDocumentMode(true);
tabBar.setTabsClosable(true);
tabBar.setMovable(true);
tabBar.setExpanding(false);
// top
tabBar.setShape(QTabBar::RoundedNorth);
// bottom
// tabBar.setShape(QTabBar::RoundedSouth);
// left
// tabBar.setShape(QTabBar::RoundedWest);
// right
// tabBar.setShape(QTabBar::RoundedEast);
const auto shortLabel = QStringLiteral("Tab %1");
const auto longLabel = QStringLiteral("An Extremely Long Tab Label %1");
QMap<int, QWidget*> tabs;
for (int i = 0; i < TabCount; i++) {
QString tabNumberString = QString::number(i);
QLabel *label = new QLabel(QStringLiteral("Tab %1 content").arg(tabNumberString));
tabs[i] = label;
label->setAlignment(Qt::AlignCenter);
stackedWidget.addWidget(label);
tabBar.addTab(shortLabel.arg(tabNumberString));
}
QObject::connect(&tabBar, &QTabBar::tabMoved, [&tabs](int from, int to) {
QWidget *thisWidget = tabs[from];
QWidget *thatWidget = tabs[to];
tabs[from] = thatWidget;
tabs[to] = thisWidget;
});
QObject::connect(&tabBar, &QTabBar::currentChanged, [&stackedWidget, &tabs](int index) {
if (index >= 0)
stackedWidget.setCurrentWidget(tabs[index]);
});
QObject::connect(&tabBar, &QTabBar::tabCloseRequested, [&stackedWidget, &tabBar, &tabs](int index) {
QWidget *widget = tabs[index];
tabBar.removeTab(index);
for (int i = index + 1; i < TabCount; i++)
tabs[i-1] = tabs[i];
int currentIndex = tabBar.currentIndex();
if (currentIndex >= 0)
stackedWidget.setCurrentWidget(tabs[currentIndex]);
delete widget;
});
QLayout *layout;
switch (tabBar.shape()) {
case QTabBar::RoundedEast:
case QTabBar::TriangularEast:
tabBar.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
layout = new QHBoxLayout(&widget);
layout->addWidget(&stackedWidget);
layout->addWidget(&tabBar);
break;
case QTabBar::RoundedWest:
case QTabBar::TriangularWest:
tabBar.setSizePolicy(QSizePolicy::Minimum, QSizePolicy::Expanding);
layout = new QHBoxLayout(&widget);
layout->addWidget(&tabBar);
layout->addWidget(&stackedWidget);
break;
case QTabBar::RoundedNorth:
case QTabBar::TriangularNorth:
tabBar.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
layout = new QVBoxLayout(&widget);
layout->addWidget(&tabBar);
layout->addWidget(&stackedWidget);
break;
case QTabBar::RoundedSouth:
case QTabBar::TriangularSouth:
tabBar.setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Minimum);
layout = new QVBoxLayout(&widget);
layout->addWidget(&stackedWidget);
layout->addWidget(&tabBar);
break;
}
TabBarForm form;
layout->addWidget(&form);
layout->setAlignment(&form, Qt::AlignHCenter);
form.ui->documentModeButton->setChecked(tabBar.documentMode());
QObject::connect(form.ui->documentModeButton, &QCheckBox::toggled, [&] {
tabBar.setDocumentMode(form.ui->documentModeButton->isChecked());
// QMacStyle (and maybe other styles) requires a re-polish to get the right font
QApplication::sendEvent(&tabBar, new QEvent(QEvent::ThemeChange));
//.........这里部分代码省略.........