How to use QTabBar in Qt
Article Metadata
Tested with
Devices(s): Symbian emulator
Compatibility
Platform(s): Qt
Article
Keywords: QTabBar
Created: james1980
(12 Jan 2009)
Last edited: hamishwillee
(11 Oct 2012)
Contents |
Overview
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
- 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);
Source File
#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
To Do
- Add widget to each tab


