本文整理汇总了C++中QTabBar::addTab方法的典型用法代码示例。如果您正苦于以下问题:C++ QTabBar::addTab方法的具体用法?C++ QTabBar::addTab怎么用?C++ QTabBar::addTab使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTabBar
的用法示例。
在下文中一共展示了QTabBar::addTab方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Buttons
Buttons()
{
QIcon icon;
icon.addFile(":/[email protected]");
QPushButton *button = new QPushButton(this);
button->setIcon(icon);
button->setText("[email protected]");
QTabBar *tab = new QTabBar(this);
tab->addTab(QIcon(":/qticon16.png"), "[email protected]");
tab->addTab(QIcon(":/[email protected]"), "[email protected]");
tab->addTab(QIcon(":/qticon16.png"), "");
tab->addTab(QIcon(":/[email protected]"), "");
tab->move(10, 100);
tab->show();
QToolBar *toolBar = new QToolBar(this);
toolBar->addAction(QIcon(":/qticon16.png"), "16");
toolBar->addAction(QIcon(":/[email protected]"), "[email protected]");
toolBar->addAction(QIcon(":/qticon32.png"), "32");
toolBar->addAction(QIcon(":/[email protected]"), "[email protected]");
toolBar->move(10, 200);
toolBar->show();
}
示例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: MakeTabBar
void FancyTabWidget::MakeTabBar(QTabBar::Shape shape, bool text, bool icons,
bool fancy) {
QTabBar* bar = new QTabBar(this);
bar->setShape(shape);
bar->setDocumentMode(true);
bar->setUsesScrollButtons(true);
bar->setElideMode(Qt::ElideRight);
if (shape == QTabBar::RoundedWest) {
bar->setIconSize(QSize(22, 22));
}
if (fancy) {
bar->setStyle(proxy_style_.get());
}
if (shape == QTabBar::RoundedNorth)
top_layout_->insertWidget(0, bar);
else
side_layout_->insertWidget(0, bar);
foreach (const Item& item, items_) {
if (item.type_ != Item::Type_Tab)
continue;
QString label = item.tab_label_;
if (shape == QTabBar::RoundedWest) {
label = QFontMetrics(font()).elidedText(label, Qt::ElideMiddle, 100);
}
int tab_id = -1;
if (icons && text)
tab_id = bar->addTab(item.tab_icon_, label);
else if (icons)
tab_id = bar->addTab(item.tab_icon_, QString());
else if (text)
tab_id = bar->addTab(label);
// Adds tooltips only in Tabs mode or IconOnlyTabs mode
// TODO in tab mode, show only if not elided, complicated since this doesn't inherit from QTabWidget
if (shape == QTabBar::RoundedNorth && ((!text && icons) || (text && !icons)))
bar->setTabToolTip(tab_id, item.tab_label_);
}
bar->setCurrentIndex(stack_->currentIndex());
connect(bar, SIGNAL(currentChanged(int)), SLOT(ShowWidget(int)));
tab_bar_ = bar;
}
示例4: QDialog
KeyboardDialog::KeyboardDialog(QWidget* parent): QDialog(parent) {
m_keyboard = new KeyboardWidget(this);
m_keyboard->setKeymap(KeyboardWidget::US);
m_keyboard->setContentsMargins(0, 0, 0, 0);
connect(m_keyboard, SIGNAL(selected(QString)), this, SIGNAL(selected(QString)));
QFrame* keyboardFrame = new QFrame(this);
keyboardFrame->setFrameShape(QFrame::WinPanel);
keyboardFrame->setFrameShadow(QFrame::Sunken);
QVBoxLayout* keyboardFrameLayout = new QVBoxLayout(keyboardFrame);
keyboardFrameLayout->addWidget(m_keyboard);
QTabBar* tabBar = new QTabBar(this);
tabBar->addTab(QIcon(":/img/keyboard/usflag.png"), "US Keymap");
tabBar->addTab(QIcon(":/img/keyboard/deflag.png"), "DE Keymap");
tabBar->addTab(QIcon(":/img/keyboard/frflag.png"), "FR Keymap");
tabBar->addTab(QIcon(":/img/keyboard/rawflag.png"), "RAW Codes");
connect(tabBar, SIGNAL(currentChanged(int)), m_keyboard, SLOT(setKeymap(int)));
QLabel* selectedLabel = new QLabel("<b>Selected <a href=\"http://www.whdload.de/docs/en/rawkey.html\">raw key code</a>: </b>", this);
selectedLabel->setOpenExternalLinks(true);
QLabel* selected = new QLabel("$--", this);
selected->setFont(QFont("Courier New", 16, QFont::Bold));
connect(m_keyboard, SIGNAL(selected(QString)), selected, SLOT(setText(QString)));
QPushButton* close = new QPushButton("Done", this);
connect(close, SIGNAL(clicked()), this, SLOT(accept()));
QVBoxLayout* mainLayout = new QVBoxLayout(this);
mainLayout->setSizeConstraint(QLayout::SetFixedSize);
mainLayout->setSpacing(0);
mainLayout->addWidget(tabBar);
mainLayout->addWidget(keyboardFrame);
mainLayout->addSpacing(8);
QHBoxLayout* selectionLayout = new QHBoxLayout();
mainLayout->addLayout(selectionLayout);
selectionLayout->addWidget(selectedLabel);
selectionLayout->addSpacing(8);
selectionLayout->addWidget(selected);
selectionLayout->addStretch();
selectionLayout->addWidget(close);
setModal(true);
setWindowTitle(__MAGE__WHDRun__NameAndVersion__ " :: WHDLoad Keyboard");
}
示例5: MakeTabBar
void FancyTabWidget::MakeTabBar(QTabBar::Shape shape, bool text, bool icons,
bool fancy) {
QTabBar* bar = new QTabBar(this);
bar->setShape(shape);
bar->setDocumentMode(true);
bar->setUsesScrollButtons(true);
if (shape == QTabBar::RoundedWest) {
bar->setIconSize(QSize(22, 22));
}
if (fancy) {
bar->setStyle(proxy_style_.data());
}
if (shape == QTabBar::RoundedNorth)
top_layout_->insertWidget(0, bar);
else
side_layout_->insertWidget(0, bar);
foreach (const Item& item, items_) {
if (item.type_ != Item::Type_Tab)
continue;
QString label = item.tab_label_;
if (shape == QTabBar::RoundedWest) {
label = QFontMetrics(font()).elidedText(label, Qt::ElideMiddle, 100);
}
int tab_id = -1;
if (icons && text)
tab_id = bar->addTab(item.tab_icon_, label);
else if (icons)
tab_id = bar->addTab(item.tab_icon_, QString());
else if (text)
tab_id = bar->addTab(label);
bar->setTabToolTip(tab_id, item.tab_label_);
}
bar->setCurrentIndex(stack_->currentIndex());
connect(bar, SIGNAL(currentChanged(int)), SLOT(ShowWidget(int)));
tab_bar_ = bar;
}
示例6: insertAtCurrentIndex
void tst_QTabBar::insertAtCurrentIndex()
{
QTabBar tabBar;
tabBar.addTab("Tab1");
QCOMPARE(tabBar.currentIndex(), 0);
tabBar.insertTab(0, "Tab2");
QCOMPARE(tabBar.currentIndex(), 1);
tabBar.insertTab(0, "Tab3");
QCOMPARE(tabBar.currentIndex(), 2);
tabBar.insertTab(2, "Tab4");
QCOMPARE(tabBar.currentIndex(), 3);
}
示例7: testCurrentChanged
void tst_QTabBar::testCurrentChanged()
{
QFETCH(int, tabToSet);
QFETCH(int, expectedCount);
QTabBar tabBar;
QSignalSpy spy(&tabBar, SIGNAL(currentChanged(int)));
tabBar.addTab("Tab1");
tabBar.addTab("Tab2");
QCOMPARE(tabBar.currentIndex(), 0);
tabBar.setCurrentIndex(tabToSet);
QCOMPARE(tabBar.currentIndex(), tabToSet);
QCOMPARE(spy.count(), expectedCount);
}
示例8: 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();
}
示例9: 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);
}
示例10: closeButton
void tst_QTabBar::closeButton()
{
QTabBar tabbar;
QCOMPARE(tabbar.tabsClosable(), false);
tabbar.setTabsClosable(true);
QCOMPARE(tabbar.tabsClosable(), true);
tabbar.addTab("foo");
QTabBar::ButtonPosition closeSide = (QTabBar::ButtonPosition)tabbar.style()->styleHint(QStyle::SH_TabBar_CloseButtonPosition, 0, &tabbar);
QTabBar::ButtonPosition otherSide = (closeSide == QTabBar::LeftSide ? QTabBar::RightSide : QTabBar::LeftSide);
QVERIFY(tabbar.tabButton(0, otherSide) == 0);
QVERIFY(tabbar.tabButton(0, closeSide) != 0);
QAbstractButton *button = static_cast<QAbstractButton*>(tabbar.tabButton(0, closeSide));
QVERIFY(button);
QSignalSpy spy(&tabbar, SIGNAL(tabCloseRequested(int)));
button->click();
QCOMPARE(tabbar.count(), 1);
QCOMPARE(spy.count(), 1);
}
示例11: tabButton
// QTabBar::setTabButton(index, closeSide, closeButton);
void tst_QTabBar::tabButton()
{
QFETCH(QTabBar::ButtonPosition, position);
QTabBar::ButtonPosition otherSide = (position == QTabBar::LeftSide ? QTabBar::RightSide : QTabBar::LeftSide);
QTabBar tabbar;
tabbar.resize(500, 200);
tabbar.show();
QTRY_VERIFY(tabbar.isVisible());
tabbar.setTabButton(-1, position, 0);
QVERIFY(tabbar.tabButton(-1, position) == 0);
QVERIFY(tabbar.tabButton(0, position) == 0);
tabbar.addTab("foo");
QCOMPARE(tabbar.count(), 1);
tabbar.setTabButton(0, position, 0);
QVERIFY(tabbar.tabButton(0, position) == 0);
QPushButton *button = new QPushButton;
button->show();
button->setText("hi");
button->resize(10, 10);
QTRY_VERIFY(button->isVisible());
QTRY_VERIFY(button->isVisible());
tabbar.setTabButton(0, position, button);
QCOMPARE(tabbar.tabButton(0, position), static_cast<QWidget *>(button));
QTRY_VERIFY(!button->isHidden());
QVERIFY(tabbar.tabButton(0, otherSide) == 0);
QCOMPARE(button->parent(), static_cast<QObject *>(&tabbar));
QVERIFY(button->pos() != QPoint(0, 0));
QPushButton *button2 = new QPushButton;
tabbar.setTabButton(0, position, button2);
QVERIFY(button->isHidden());
}
示例12: Style
Style() {
row1 = new QHBoxLayout();
setLayout(row1);
button = new QPushButton();
button->setText("Test Button");
row1->addWidget(button);
lineEdit = new QLineEdit();
lineEdit->setText("Test Lineedit");
row1->addWidget(lineEdit);
slider = new QSlider();
row1->addWidget(slider);
row1->addWidget(new QSpinBox);
row1->addWidget(new QScrollBar);
QTabBar *tab = new QTabBar();
tab->addTab("Foo");
tab->addTab("Bar");
row1->addWidget(tab);
}
示例13: sizeHints
void tst_QTabBar::sizeHints()
{
QTabBar tabBar;
QSKIP("To be fixed on Mac (font size below not large enough) and Linux QWS (probably too large for the screen).", SkipSingle);
tabBar.setFont(QFont("Arial", 10));
tabBar.addTab("tab 01");
tabBar.addTab("tab 02");
tabBar.addTab("tab 03");
tabBar.addTab("tab 04");
tabBar.addTab("tab 05");
tabBar.addTab("tab 06");
tabBar.addTab("This is tab7");
tabBar.addTab("This is tab8");
tabBar.addTab("This is tab9 with a very long title");
// No eliding and no scrolling -> tabbar becomes very wide
tabBar.setUsesScrollButtons(false);
tabBar.setElideMode(Qt::ElideNone);
// qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint();
QVERIFY(tabBar.minimumSizeHint().width() > 700);
QVERIFY(tabBar.sizeHint().width() > 700);
// Scrolling enabled -> no reason to become very wide
tabBar.setUsesScrollButtons(true);
// qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint();
QVERIFY(tabBar.minimumSizeHint().width() < 200);
QVERIFY(tabBar.sizeHint().width() > 700); // unchanged
// Eliding enabled -> no reason to become very wide
tabBar.setUsesScrollButtons(false);
tabBar.setElideMode(Qt::ElideRight);
// qDebug() << tabBar.minimumSizeHint() << tabBar.sizeHint();
QVERIFY(tabBar.minimumSizeHint().width() < 500);
QVERIFY(tabBar.sizeHint().width() > 700); // unchanged
tabBar.addTab("This is tab10 with a very long title");
QVERIFY(tabBar.minimumSizeHint().width() < 600);
QVERIFY(tabBar.sizeHint().width() > 700); // unchanged
}
示例14: setupWidgets
void managementWidget::setupWidgets()
{
QTab t;
top = new QBoxLayout(this,QBoxLayout::TopToBottom);
vPan = new QSplitter(QSplitter::Horizontal, this);
top->addWidget(vPan);
// the left panel
leftpanel = new QFrame(vPan);
leftbox = new QBoxLayout(leftpanel,QBoxLayout::TopToBottom);
QTabBar *ltab = new QTabBar(leftpanel);
treeList = new KpTreeList(leftpanel);
for (int i = 0; i < 4; i++) {
QTab *t = new QTab();
t->setText( tType[i] );
ltab->addTab(t);
}
// Quick Search Bar
searchToolBar = new KToolBar( leftpanel, "search toolbar");
QToolButton *clearSearch = new QToolButton(searchToolBar);
clearSearch->setTextLabel(i18n("Clear Search"), true);
clearSearch->setIconSet(SmallIconSet(QApplication::reverseLayout() ? "clear_left"
: "locationbar_erase"));
(void) new QLabel(i18n("Search: "),searchToolBar);
searchLine = new KpListViewSearchLine(searchToolBar, treeList);
// searchLine->setKeepParentsVisible(false);
connect( clearSearch, SIGNAL( pressed() ), searchLine, SLOT( clear() ));
QValueList<int> clist; clist.append(0); clist.append(2);
searchLine->setSearchColumns(clist);
searchToolBar->setStretchableWidget( searchLine );
connect( treeList, SIGNAL( cleared() ), searchLine, SLOT( clear() ));
connect(ltab,SIGNAL(selected (int)),SLOT(tabChanged(int)));
ltab->setCurrentTab(treeList->treeType);
leftbox->addWidget(ltab,10);
leftbox->addWidget(searchToolBar,10);
leftbox->addWidget(treeList,10);
leftbox->addStretch();
lbuttons = new QBoxLayout(QBoxLayout::LeftToRight);
luinstButton = new QPushButton(i18n("Uninstall Marked"),leftpanel);
luinstButton->setEnabled(FALSE);
connect(luinstButton,SIGNAL(clicked()),
SLOT(uninstallMultClicked()));
linstButton = new QPushButton(i18n("Install Marked"),leftpanel);
linstButton->setEnabled(FALSE);
connect(linstButton,SIGNAL(clicked()),
SLOT(installMultClicked()));
leftbox->addLayout(lbuttons,0); // top level layout as child
// Setup the `buttons' layout
lbuttons->addWidget(linstButton,1,AlignBottom);
lbuttons->addWidget(luinstButton,1,AlignBottom);
lbuttons->addStretch(1);
connect(treeList, SIGNAL(selectionChanged(QListViewItem *)),
SLOT(packageHighlighted(QListViewItem *)));
// the right panel
rightpanel = new QFrame(vPan);
rightbox = new QBoxLayout(rightpanel,QBoxLayout::TopToBottom);
packageDisplay = new packageDisplayWidget(rightpanel);
// connect(this, SIGNAL(changePackage(packageInfo *)),
// packageDisplay, SLOT(changePackage(packageInfo *)));
rbuttons = new QBoxLayout(QBoxLayout::LeftToRight);
uinstButton = new QPushButton(i18n("Uninstall"),rightpanel);
uinstButton->setEnabled(FALSE);
connect(uinstButton,SIGNAL(clicked()),
SLOT(uninstallSingleClicked()));
instButton = new QPushButton(i18n("Install"),rightpanel);
instButton->setEnabled(FALSE);
connect(instButton,SIGNAL(clicked()),
SLOT(installSingleClicked()));
// Setup the `right panel' layout
rightbox->addWidget(packageDisplay,10);
rightbox->addLayout(rbuttons,0); // top level layout as child
// Setup the `buttons' layout
rbuttons->addWidget(instButton,1);
rbuttons->addWidget(uinstButton,1);
rbuttons->addStretch(1);
//.........这里部分代码省略.........
示例15: QFrame
ItemLibraryWidget::ItemLibraryWidget(QWidget *parent) :
QFrame(parent),
m_itemIconSize(24, 24),
m_resIconSize(24, 24),
m_iconProvider(m_resIconSize),
m_itemsView(new QQuickView()),
m_resourcesView(new ItemLibraryTreeView(this)),
m_filterFlag(QtBasic)
{
ItemLibraryModel::registerQmlTypes();
setWindowTitle(tr("Library", "Title of library view"));
/* create Items view and its model */
m_itemsView->setResizeMode(QQuickView::SizeRootObjectToView);
m_itemLibraryModel = new ItemLibraryModel(this);
QQmlContext *rootContext = m_itemsView->rootContext();
rootContext->setContextProperty(QStringLiteral("itemLibraryModel"), m_itemLibraryModel.data());
rootContext->setContextProperty(QStringLiteral("itemLibraryIconWidth"), m_itemIconSize.width());
rootContext->setContextProperty(QStringLiteral("itemLibraryIconHeight"), m_itemIconSize.height());
rootContext->setContextProperty(QStringLiteral("rootView"), this);
m_itemsView->rootContext()->setContextProperty(QStringLiteral("highlightColor"), Utils::StyleHelper::notTooBrightHighlightColor());
/* create Resources view and its model */
m_resourcesFileSystemModel = new QFileSystemModel(this);
m_resourcesFileSystemModel->setIconProvider(&m_iconProvider);
m_resourcesView->setModel(m_resourcesFileSystemModel.data());
m_resourcesView->setIconSize(m_resIconSize);
/* create image provider for loading item icons */
m_itemsView->engine()->addImageProvider(QStringLiteral("qmldesigner_itemlibrary"), new Internal::ItemLibraryImageProvider);
/* other widgets */
QTabBar *tabBar = new QTabBar(this);
tabBar->addTab(tr("QML Types", "Title of library QML types view"));
tabBar->addTab(tr("Resources", "Title of library resources view"));
tabBar->addTab(tr("Imports", "Title of library imports view"));
tabBar->setSizePolicy(QSizePolicy::Fixed, QSizePolicy::Fixed);
connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(setCurrentIndexOfStackedWidget(int)));
connect(tabBar, SIGNAL(currentChanged(int)), this, SLOT(updateSearch()));
m_filterLineEdit = new Utils::FancyLineEdit(this);
m_filterLineEdit->setObjectName(QStringLiteral("itemLibrarySearchInput"));
m_filterLineEdit->setPlaceholderText(tr("<Filter>", "Library search input hint text"));
m_filterLineEdit->setDragEnabled(false);
m_filterLineEdit->setMinimumWidth(75);
m_filterLineEdit->setTextMargins(0, 0, 20, 0);
m_filterLineEdit->setFiltering(true);
QWidget *lineEditFrame = new QWidget(this);
lineEditFrame->setObjectName(QStringLiteral("itemLibrarySearchInputFrame"));
QGridLayout *lineEditLayout = new QGridLayout(lineEditFrame);
lineEditLayout->setMargin(2);
lineEditLayout->setSpacing(0);
lineEditLayout->addItem(new QSpacerItem(5, 3, QSizePolicy::Fixed, QSizePolicy::Fixed), 0, 0, 1, 3);
lineEditLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Fixed, QSizePolicy::Fixed), 1, 0);
lineEditLayout->addWidget(m_filterLineEdit.data(), 1, 1, 1, 1);
lineEditLayout->addItem(new QSpacerItem(5, 5, QSizePolicy::Fixed, QSizePolicy::Fixed), 1, 2);
connect(m_filterLineEdit.data(), SIGNAL(filterChanged(QString)), this, SLOT(setSearchFilter(QString)));
QWidget *container = createWindowContainer(m_itemsView.data());
m_stackedWidget = new QStackedWidget(this);
m_stackedWidget->addWidget(container);
m_stackedWidget->addWidget(m_resourcesView.data());
QWidget *spacer = new QWidget(this);
spacer->setObjectName(QStringLiteral("itemLibrarySearchInputSpacer"));
spacer->setFixedHeight(4);
QGridLayout *layout = new QGridLayout(this);
layout->setContentsMargins(0, 0, 0, 0);
layout->setSpacing(0);
layout->addWidget(tabBar, 0, 0, 1, 1);
layout->addWidget(spacer, 1, 0);
layout->addWidget(lineEditFrame, 2, 0, 1, 1);
layout->addWidget(m_stackedWidget.data(), 3, 0, 1, 1);
setResourcePath(QDir::currentPath());
setSearchFilter(QString());
/* style sheets */
setStyleSheet(QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/stylesheet.css")));
m_resourcesView->setStyleSheet(QString::fromUtf8(Utils::FileReader::fetchQrc(":/qmldesigner/scrollbar.css")));
m_qmlSourceUpdateShortcut = new QShortcut(QKeySequence(Qt::CTRL + Qt::Key_F5), this);
connect(m_qmlSourceUpdateShortcut, SIGNAL(activated()), this, SLOT(reloadQmlSource()));
// init the first load of the QML UI elements
reloadQmlSource();
}