×
Namespaces

Variants
Actions

How to use QTabBar in Qt

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata
Tested with
Devices(s): Symbian emulator
Compatibility
Platform(s): Qt
Symbian
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)

Tab.JPG

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

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);
Scrolltab.JPG

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

Tabbar.jpg

To Do

  • Add widget to each tab
This page was last modified on 11 October 2012, at 04:17.
90 page views in the last 30 days.

Was this page helpful?

Your feedback about this content is important. Let us know what you think.

 

Thank you!

We appreciate your feedback.

×