Namespaces
Variants
Actions
Revision as of 04:17, 11 October 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

How to use QTabBar in Qt

Jump to: navigation, search
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)

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
405 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved