本文整理汇总了C++中QTabBar::removeTab方法的典型用法代码示例。如果您正苦于以下问题:C++ QTabBar::removeTab方法的具体用法?C++ QTabBar::removeTab怎么用?C++ QTabBar::removeTab使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTabBar
的用法示例。
在下文中一共展示了QTabBar::removeTab方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: removeLastTab
void tst_QTabBar::removeLastTab()
{
QTabBar tabbar;
QSignalSpy spy(&tabbar, SIGNAL(currentChanged(int)));
int index = tabbar.addTab("foo");
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.at(0).at(0).toInt(), index);
spy.clear();
tabbar.removeTab(index);
QCOMPARE(spy.count(), 1);
QCOMPARE(spy.at(0).at(0).toInt(), -1);
spy.clear();
}
示例2: removeTab
void tst_QTabBar::removeTab()
{
QTabBar tabbar;
QFETCH(int, currentIndex);
QFETCH(int, deleteIndex);
tabbar.addTab("foo");
tabbar.addTab("bar");
tabbar.addTab("baz");
tabbar.setCurrentIndex(currentIndex);
QSignalSpy spy(&tabbar, SIGNAL(currentChanged(int)));
tabbar.removeTab(deleteIndex);
QTEST(spy.count(), "spyCount");
QTEST(tabbar.currentIndex(), "finalIndex");
}
示例3: selectionBehaviorOnRemove
void tst_QTabBar::selectionBehaviorOnRemove()
{
QFETCH(QTabBar::SelectionBehavior, selectionBehavior);
QFETCH(int, tabs);
QFETCH(IntList, select);
QFETCH(IntList, remove);
QFETCH(int, expected);
QTabBar tabbar;
tabbar.setSelectionBehaviorOnRemove(selectionBehavior);
while(--tabs >= 0)
tabbar.addTab(QString::number(tabs));
QCOMPARE(tabbar.currentIndex(), 0);
while(!select.isEmpty())
tabbar.setCurrentIndex(select.takeFirst());
while(!remove.isEmpty())
tabbar.removeTab(remove.takeFirst());
QVERIFY(tabbar.count() > 0);
QCOMPARE(tabbar.currentIndex(), expected);
}
示例4: Dispose
void NativeTabItem::Dispose()
{
QTabBar* widget = parent->GetTabFolder();
int index = parent->IndexOf(this);
widget->removeTab(index); // this calls QCTabBar::tabRemoved
}
示例5: 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));
//.........这里部分代码省略.........