×
Namespaces

Variants
Actions

Archived:How to use a QTabWidget

From Nokia Developer Wiki
Jump to: navigation, search

Archived.pngArchived: This article is archived because it is not considered relevant for third-party developers creating commercial solutions today. If you think this article is still relevant, let us know by adding the template {{ReviewForRemovalFromArchive|user=~~~~|write your reason here}}.

Qt Quick should be used for all UI development on mobile devices. The approach described in this article (based on QWidget) is deprecated.

This example shows how to create a QTabWidget, and add other widgets to the different tabs.

Article Metadata
Tested with
Devices(s): Qt Creator IDE & S60 Emulator
Compatibility
Platform(s): S60 3rd Edition FP1, S60 3rd Edition FP2, S60 5th Edition
Symbian
Platform Security
Signing Required: Self-Signed
Capabilities: None
Article
Keywords: QTabBar
Created: mind_freak (13 Mar 2009)
Last edited: hamishwillee (11 Oct 2012)

Contents

Preconditions

  • Download and install the Qt SDK

How this Widget is created

  1. Create a QTabWidget.
  2. Create a QWidget for each of the pages in the tab dialog, but do not specify parent widgets for them.
  3. Insert child widgets into the page widget, using layouts to position them as normal.
  4. Call addTab() or insertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut.


Features

  • We can drag any of the the tab bar in any positon in window area only.
  • If Their are large number of tab we can inset setScroll event and have a scroll bar to switch between TAB BAR


Various Function

  • This property controls how items are elided when there is not enough space to show them for a given tab bar size.
wid->setElideMode(Qt::ElideRight);
  • To add Tab To Tab Bar
 wid->addTab(window,str);
  • This property holds the position of the tabs in this tab widget.
wid->setTabPosition(QTabWidget::South);

Tab003.JPG

  • This property holds this property holds whether the user can move the tabs within the tabbar area
wid->setMovable(1);

Tabwidget005.jpg

  • This property holds whether or not a tab bar should place close buttons on each tab.
wid->setTabsClosable(1);

Tab002.JPG


Source Code

#include <QtGui/QApplication>
#include "tabwidgetdialog.h"
#include <QtGui>
#include <QApplication>
#include<QWidget>
#include<QGroupBox>
#include<QCheckBox>
#include<QTabWidget>
#include<QString>
#include<QRadioButton>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QTabWidget *wid=new QTabWidget();
QString str("Nokia N-Series");
QString str1("Nokia E-Series");
QString str2("I LOVE MY INDIA");
QWidget *window=new QWidget();
QVBoxLayout *layout=new QVBoxLayout();
QVBoxLayout *layout1=new QVBoxLayout();
QGroupBox *group=new QGroupBox();
group->resize(300,300);
group->setLayout(layout);
group->setAlignment(Qt::AlignHCenter);
group->setCheckable(true);
QCheckBox *chk1=new QCheckBox("Nokia N97");
QCheckBox *chk2=new QCheckBox("Nokia N96");
QCheckBox *chk3=new QCheckBox("Nokia N73");
group->setTitle("&Nokia Phones");
layout1->addWidget(group);
layout->addWidget(chk1);
layout->addWidget(chk2);
layout->addWidget(chk3);
window->setLayout(layout1);
window->show();
QWidget *wdn=new QWidget();
QVBoxLayout *lay=new QVBoxLayout();
QVBoxLayout *lay1=new QVBoxLayout();
QGroupBox *group1=new QGroupBox();
group1->resize(300,300);
group1->setLayout(lay);
group1->setAlignment(Qt::AlignHCenter);
group1->setCheckable(true);
QCheckBox *chk4=new QCheckBox("Nokia E51");
QCheckBox *chk5=new QCheckBox("Nokia E52");
QCheckBox *chk6=new QCheckBox("Nokia E75");
group1->setTitle("&Phones");
lay1->addWidget(group1);
lay->addWidget(chk4);
lay->addWidget(chk5);
lay->addWidget(chk6);
wdn->setLayout(lay1);
wdn->show();
QWidget *wd=new QWidget();
QVBoxLayout *ly=new QVBoxLayout();
QVBoxLayout *ly1=new QVBoxLayout();
QGroupBox *group2=new QGroupBox();
group2->resize(300,300);
group2->setLayout(ly);
group2->setAlignment(Qt::AlignHCenter);
group2->setCheckable(true);
QRadioButton *Rad1=new QRadioButton("J&K");
QRadioButton *Rad2=new QRadioButton("DELHI");
QRadioButton *Rad3=new QRadioButton("AHMD");
QRadioButton *Rad4=new QRadioButton("Kolkata");
group2->setTitle("INDIA");
ly1->addWidget(group2);
ly->addWidget(Rad1);
ly->addWidget(Rad2);
ly->addWidget(Rad3);
ly->addWidget(Rad4);
wd->setLayout(ly1);
wd->show();
wid->setElideMode(Qt::ElideRight);
wid->setMovable(1);
// wid->setTabPosition(QTabWidget::South); // This is used to set The tab orientation.
wid->setTabsClosable(1); //Used to set the close button on every tab
wid->setDocumentMode(1);
wid->addTab(window,str);
wid->addTab(wdn,str1);
wid->addTab(wd,str2);
wid->showMaximized();
wid->setStyleSheet("* { background-color:rgb(150,147,88); padding: 7px ; color:rgb(255,255,255)}");
return a.exec();
}

Screenchot in S60 Emulator

Tab001.jpg

This page was last modified on 11 October 2012, at 01:14.
128 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.

×