How to use QTabBar in Qt
Jump to navigation
Jump to search
Overview[edit | edit source]
This code snippet demonstrates how to create a tab bar in Qt. Using a TabBar one can arrange widgets on a different page and display them one by one.
Various Function[edit | edit source]
- To add the Tab in QTabBar.
QString str="tab1"; QString str1="tab2"; QString str2="tab3"; tabbar->addTab(str); tabbar->addTab(str1); tabbar->addTab(str2)
- This property is used to shape the tab in TabBar
tabbar->setShape(QTabBar::RoundedWest);
- when their are many tabs in widget the it is needed of an tabscroll Bar.When there are too many tabs in a tab bar for its size, the tab bar can either choose to expand its size or to add buttons that allow you to scroll through the tabs.
tabbar->setUsesScrollButtons(1);
File:Scrolltab.JPG
Source File[edit | edit source]
- include <QApplication>
- include <QTabBar>
- include <QWidget>
- include <QVBoxLayout>
- include <QString>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
QWidget *mainwin = new QWidget;
QTabBar *tabbar = new QTabBar;
QString str="tab1";
QString str1="tab2";
QVBoxLayout *layout = new QVBoxLayout;
mainwin->setStyleSheet("*{background-color:rgb(111,135,67);}");
tabbar->addTab(str);
tabbar->addTab(str1);
tabbar->setShape(QTabBar::TriangularNorth);
layout->addWidget(tabbar);
mainwin->setLayout(layout);
mainwin->showMaximized();
return app.exec();
}
Screenshot[edit | edit source]
To Do[edit | edit source]
- Add widget to each tab