We believe we've resolved the timeouts on page updates following yesterday's server operating system upgrade. Please let us know if you notice any further issues or performance degradation.

How to use QTabBar in Qt

From Qt Wiki
Jump to navigation Jump to search

Template:ArticleMetaData

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)

File:Tab.JPG

  • This property is used to shape the tab in TabBar
tabbar->setShape(QTabBar::RoundedWest);
 

File:Tab1.JPG

  • 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]

  1. include <QApplication>
  2. include <QTabBar>
  3. include <QWidget>
  4. include <QVBoxLayout>
  5. 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]

File:Tabbar.jpg

To Do[edit | edit source]

  • Add widget to each tab