Movatterモバイル変換


[0]ホーム

URL:


We bake cookies in your browser for a better experience. Using this site means that you consent.Read More

Menu

Qt Documentation

QTabWidget Class

TheQTabWidget class provides a stack of tabbed widgets.More...

Header:#include <QTabWidget>
Inherits:QWidget

Public Types

enumTabPosition { North, South, West, East }
enumTabShape { Rounded, Triangular }

Properties

Public Functions

QTabWidget(QWidget * parent = 0)
~QTabWidget()
intaddTab(QWidget * page, const QString & label)
intaddTab(QWidget * page, const QIcon & icon, const QString & label)
voidclear()
QWidget *cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const
intcount() const
intcurrentIndex() const
QWidget *currentWidget() const
booldocumentMode() const
Qt::TextElideModeelideMode() const
QSizeiconSize() const
intindexOf(QWidget * w) const
intinsertTab(int index, QWidget * page, const QString & label)
intinsertTab(int index, QWidget * page, const QIcon & icon, const QString & label)
boolisMovable() const
boolisTabEnabled(int index) const
voidremoveTab(int index)
voidsetCornerWidget(QWidget * widget, Qt::Corner corner = Qt::TopRightCorner)
voidsetDocumentMode(bool set)
voidsetElideMode(Qt::TextElideMode)
voidsetIconSize(const QSize & size)
voidsetMovable(bool movable)
voidsetTabEnabled(int index, bool enable)
voidsetTabIcon(int index, const QIcon & icon)
voidsetTabPosition(TabPosition)
voidsetTabShape(TabShape s)
voidsetTabText(int index, const QString & label)
voidsetTabToolTip(int index, const QString & tip)
voidsetTabWhatsThis(int index, const QString & text)
voidsetTabsClosable(bool closeable)
voidsetUsesScrollButtons(bool useButtons)
QIcontabIcon(int index) const
TabPositiontabPosition() const
TabShapetabShape() const
QStringtabText(int index) const
QStringtabToolTip(int index) const
QStringtabWhatsThis(int index) const
booltabsClosable() const
boolusesScrollButtons() const
QWidget *widget(int index) const

Reimplemented Public Functions

virtual intheightForWidth(int width) const
virtual QSizeminimumSizeHint() const
virtual QSizesizeHint() const

Public Slots

voidsetCurrentIndex(int index)
voidsetCurrentWidget(QWidget * widget)
  • 19 public slots inherited fromQWidget
  • 1 public slot inherited fromQObject

Signals

voidcurrentChanged(int index)
voidtabCloseRequested(int index)

Protected Functions

voidinitStyleOption(QStyleOptionTabWidgetFrame * option) const
voidsetTabBar(QTabBar * tb)
QTabBar *tabBar() const
virtual voidtabInserted(int index)
virtual voidtabRemoved(int index)

Reimplemented Protected Functions

virtual voidchangeEvent(QEvent * ev)
virtual boolevent(QEvent * ev)
virtual voidkeyPressEvent(QKeyEvent * e)
virtual voidpaintEvent(QPaintEvent * event)
virtual voidresizeEvent(QResizeEvent * e)
virtual voidshowEvent(QShowEvent *)
  • 37 protected functions inherited fromQWidget
  • 8 protected functions inherited fromQObject
  • 1 protected function inherited fromQPaintDevice

Additional Inherited Members

  • 4 static public members inherited fromQWidget
  • 7 static public members inherited fromQObject
  • 1 protected slot inherited fromQWidget

Detailed Description

TheQTabWidget class provides a stack of tabbed widgets.

A tab widget provides a tab bar (seeQTabBar) and a "page area" that is used to display pages related to each tab. By default, the tab bar is shown above the page area, but different configurations are available (seeTabPosition). Each tab is associated with a different widget (called a page). Only the current page is shown in the page area; all the other pages are hidden. The user can show a different page by clicking on its tab or by pressing its Alt+letter shortcut if it has one.

The normal way to useQTabWidget is to do the following:

  1. Create aQTabWidget.
  2. Create aQWidget 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. CalladdTab() orinsertTab() to put the page widgets into the tab widget, giving each tab a suitable label with an optional keyboard shortcut.

The position of the tabs is defined bytabPosition, their shape bytabShape.

The signalcurrentChanged() is emitted when the user selects a page.

The current page index is available ascurrentIndex(), the current page widget withcurrentWidget(). You can retrieve a pointer to a page widget with a given index usingwidget(), and can find the index position of a widget withindexOf(). UsesetCurrentWidget() orsetCurrentIndex() to show a particular page.

You can change a tab's text and icon usingsetTabText() orsetTabIcon(). A tab and its associated page can be removed withremoveTab().

Each tab is either enabled or disabled at any given time (seesetTabEnabled()). If a tab is enabled, the tab text is drawn normally and the user can select that tab. If it is disabled, the tab is drawn in a different way and the user cannot select that tab. Note that even if a tab is disabled, the page can still be visible, for example if all of the tabs happen to be disabled.

Tab widgets can be a very good way to split up a complex dialog. An alternative is to use aQStackedWidget for which you provide some means of navigating between pages, for example, aQToolBar or aQListWidget.

Most of the functionality inQTabWidget is provided by aQTabBar (at the top, providing the tabs) and aQStackedWidget (most of the area, organizing the individual pages).

Screenshot of a Windows XP style tab widgetScreenshot of a Macintosh style tab widgetScreenshot of a Plastique style tab widget
A Windows XP style tab widget.A Macintosh style tab widget.A Plastique style tab widget.

See alsoQTabBar,QStackedWidget,QToolBox, andTab Dialog Example.

Member Type Documentation

enum QTabWidget::TabPosition

This enum type defines whereQTabWidget draws the tab row:

ConstantValueDescription
QTabWidget::North0The tabs are drawn above the pages.
QTabWidget::South1The tabs are drawn below the pages.
QTabWidget::West2The tabs are drawn to the left of the pages.
QTabWidget::East3The tabs are drawn to the right of the pages.

enum QTabWidget::TabShape

This enum type defines the shape of the tabs:

ConstantValueDescription
QTabWidget::Rounded0The tabs are drawn with a rounded look. This is the default shape.
QTabWidget::Triangular1The tabs are drawn with a triangular look.

Property Documentation

count : constint

This property holds the number of tabs in the tab bar.

By default, this property contains a value of 0.

Access functions:

intcount() const

currentIndex :int

This property holds the index position of the current tab page.

The current index is -1 if there is no current widget.

By default, this property contains a value of -1 because there are initially no tabs in the widget.

Access functions:

intcurrentIndex() const
voidsetCurrentIndex(int index)

Notifier signal:

voidcurrentChanged(int index)

documentMode :bool

This property holds whether or not the tab widget is rendered in a mode suitable for document pages. This is the same as document mode on Mac OS X.

When this property is set the tab widget frame is not rendered. This mode is useful for showing document-type pages where the page covers most of the tab widget area.

This property was introduced in Qt 4.5.

Access functions:

booldocumentMode() const
voidsetDocumentMode(bool set)

See alsoelideMode,QTabBar::documentMode,QTabBar::usesScrollButtons, andQStyle::SH_TabBar_PreferNoArrows.

elideMode :Qt::TextElideMode

This property holds how to elide text in the tab bar.

This property controls how items are elided when there is not enough space to show them for a given tab bar size.

By default the value is style dependant.

This property was introduced in Qt 4.2.

Access functions:

Qt::TextElideModeelideMode() const
voidsetElideMode(Qt::TextElideMode)

See alsoQTabBar::elideMode,usesScrollButtons, andQStyle::SH_TabBar_ElideMode.

iconSize :QSize

This property holds the size for icons in the tab bar.

The default value is style-dependent. This is the maximum size that the icons will have. Icons are not scaled up if they are of smaller size.

This property was introduced in Qt 4.2.

Access functions:

QSizeiconSize() const
voidsetIconSize(const QSize & size)

See alsoQTabBar::iconSize.

movable :bool

This property holds this property holds whether the user can move the tabs within the tabbar area.

By default, this property is false;

This property was introduced in Qt 4.5.

Access functions:

boolisMovable() const
voidsetMovable(bool movable)

tabPosition :TabPosition

This property holds the position of the tabs in this tab widget.

Possible values for this property are described by theTabPosition enum.

By default, this property is set toNorth.

Access functions:

TabPositiontabPosition() const
voidsetTabPosition(TabPosition)

See alsoTabPosition.

tabShape :TabShape

This property holds the shape of the tabs in this tab widget.

Possible values for this property areQTabWidget::Rounded (default) orQTabWidget::Triangular.

Access functions:

TabShapetabShape() const
voidsetTabShape(TabShape s)

See alsoTabShape.

tabsClosable :bool

This property holds whether close buttons are automatically added to each tab.

This property was introduced in Qt 4.5.

Access functions:

booltabsClosable() const
voidsetTabsClosable(bool closeable)

See alsoQTabBar::tabsClosable().

usesScrollButtons :bool

This property holds whether or not a tab bar should use buttons to scroll tabs when it has many tabs.

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.

By default the value is style dependant.

This property was introduced in Qt 4.2.

Access functions:

boolusesScrollButtons() const
voidsetUsesScrollButtons(bool useButtons)

See alsoelideMode,QTabBar::usesScrollButtons, andQStyle::SH_TabBar_PreferNoArrows.

Member Function Documentation

QTabWidget::QTabWidget(QWidget * parent = 0)

Constructs a tabbed widget with parentparent.

QTabWidget::~QTabWidget()

Destroys the tabbed widget.

int QTabWidget::addTab(QWidget * page, constQString & label)

Adds a tab with the givenpage andlabel to the tab widget, and returns the index of the tab in the tab bar.

If the tab'slabel contains an ampersand, the letter following the ampersand is used as a shortcut for the tab, e.g. if the label is "Bro&wse" then Alt+W becomes a shortcut which will move the focus to this tab.

Note:If you call addTab() aftershow(), the layout system will try to adjust to the changes in its widgets hierarchy and may cause flicker. To prevent this, you can set theQWidget::updatesEnabled property to false prior to changes; remember to set the property to true when the changes are done, making the widget receive paint events again.

See alsoinsertTab().

int QTabWidget::addTab(QWidget * page, constQIcon & icon, constQString & label)

This is an overloaded function.

Adds a tab with the givenpage,icon, andlabel to the tab widget, and returns the index of the tab in the tab bar.

This function is the same asaddTab(), but with an additionalicon.

[virtual protected]void QTabWidget::changeEvent(QEvent * ev)

Reimplemented fromQWidget::changeEvent().

void QTabWidget::clear()

Removes all the pages, but does not delete them. Calling this function is equivalent to callingremoveTab() until the tab widget is empty.

QWidget * QTabWidget::cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const

Returns the widget shown in thecorner of the tab widget or 0.

See alsosetCornerWidget().

QWidget * QTabWidget::currentWidget() const

Returns a pointer to the page currently being displayed by the tab dialog. The tab dialog does its best to make sure that this value is never 0 (but if you try hard enough, it can be).

See alsocurrentIndex() andsetCurrentWidget().

[virtual protected]bool QTabWidget::event(QEvent * ev)

Reimplemented fromQObject::event().

[virtual]int QTabWidget::heightForWidth(int width) const

Reimplemented fromQWidget::heightForWidth().

This function was introduced in Qt 4.8.

int QTabWidget::indexOf(QWidget * w) const

Returns the index position of the page occupied by the widgetw, or -1 if the widget cannot be found.

[protected]void QTabWidget::initStyleOption(QStyleOptionTabWidgetFrame * option) const

Initializeoption with the values from thisQTabWidget. This method is useful for subclasses when they need aQStyleOptionTabWidgetFrame, but don't want to fill in all the information themselves.

See alsoQStyleOption::initFrom() andQTabBar::initStyleOption().

int QTabWidget::insertTab(int index,QWidget * page, constQString & label)

Inserts a tab with the givenlabel andpage into the tab widget at the specifiedindex, and returns the index of the inserted tab in the tab bar.

The label is displayed in the tab and may vary in appearance depending on the configuration of the tab widget.

If the tab'slabel contains an ampersand, the letter following the ampersand is used as a shortcut for the tab, e.g. if the label is "Bro&wse" then Alt+W becomes a shortcut which will move the focus to this tab.

Ifindex is out of range, the tab is simply appended. Otherwise it is inserted at the specified position.

If theQTabWidget was empty before this function is called, the new page becomes the current page. Inserting a new tab at an index less than or equal to the current index will increment the current index, but keep the current page.

Note:If you call insertTab() aftershow(), the layout system will try to adjust to the changes in its widgets hierarchy and may cause flicker. To prevent this, you can set theQWidget::updatesEnabled property to false prior to changes; remember to set the property to true when the changes are done, making the widget receive paint events again.

See alsoaddTab().

int QTabWidget::insertTab(int index,QWidget * page, constQIcon & icon, constQString & label)

This is an overloaded function.

Inserts a tab with the givenlabel,page, andicon into the tab widget at the specifiedindex, and returns the index of the inserted tab in the tab bar.

This function is the same asinsertTab(), but with an additionalicon.

bool QTabWidget::isTabEnabled(int index) const

Returns true if the page at positionindex is enabled; otherwise returns false.

See alsosetTabEnabled() andQWidget::isEnabled().

[virtual protected]void QTabWidget::keyPressEvent(QKeyEvent * e)

Reimplemented fromQWidget::keyPressEvent().

[virtual]QSize QTabWidget::minimumSizeHint() const

Reimplemented fromQWidget::minimumSizeHint().

Returns a suitable minimum size for the tab widget.

[virtual protected]void QTabWidget::paintEvent(QPaintEvent * event)

Reimplemented fromQWidget::paintEvent().

Paints the tab widget's tab bar in response to the paintevent.

void QTabWidget::removeTab(int index)

Removes the tab at positionindex from this stack of widgets. The page widget itself is not deleted.

See alsoaddTab() andinsertTab().

[virtual protected]void QTabWidget::resizeEvent(QResizeEvent * e)

Reimplemented fromQWidget::resizeEvent().

void QTabWidget::setCornerWidget(QWidget * widget,Qt::Corner corner = Qt::TopRightCorner)

Sets the givenwidget to be shown in the specifiedcorner of the tab widget. The geometry of the widget is determined based on the widget'ssizeHint() and thestyle().

Only the horizontal element of thecorner will be used.

Passing 0 shows no widget in the corner.

Any previously set corner widget is hidden.

All widgets set here will be deleted by the tab widget when it is destroyed unless you separately reparent the widget after setting some other corner widget (or 0).

Note: Corner widgets are designed forNorth andSouth tab positions; other orientations are known to not work properly.

See alsocornerWidget() andsetTabPosition().

[slot]void QTabWidget::setCurrentWidget(QWidget * widget)

Makeswidget the current widget. Thewidget used must be a page in this tab widget.

See alsoaddTab(),setCurrentIndex(), andcurrentWidget().

[protected]void QTabWidget::setTabBar(QTabBar * tb)

Replaces the dialog'sQTabBar heading with the tab bartb. Note that this must be calledbefore any tabs have been added, or the behavior is undefined.

See alsotabBar().

void QTabWidget::setTabEnabled(int index,bool enable)

Ifenable is true, the page at positionindex is enabled; otherwise the page at positionindex is disabled. The page's tab is redrawn appropriately.

QTabWidget usesQWidget::setEnabled() internally, rather than keeping a separate flag.

Note that even a disabled tab/page may be visible. If the page is visible already,QTabWidget will not hide it; if all the pages are disabled,QTabWidget will show one of them.

See alsoisTabEnabled() andQWidget::setEnabled().

void QTabWidget::setTabIcon(int index, constQIcon & icon)

This is an overloaded function.

Sets theicon for the tab at positionindex.

See alsotabIcon().

void QTabWidget::setTabText(int index, constQString & label)

Defines a newlabel for the page at positionindex's tab.

If the provided text contains an ampersand character ('&'), a shortcut is automatically created for it. The character that follows the '&' will be used as the shortcut key. Any previous shortcut will be overwritten, or cleared if no shortcut is defined by the text. See theQShortcut documentation for details (to display an actual ampersand, use '&&').

See alsotabText().

void QTabWidget::setTabToolTip(int index, constQString & tip)

Sets the tab tool tip for the page at positionindex totip.

See alsotabToolTip().

void QTabWidget::setTabWhatsThis(int index, constQString & text)

Sets the What's This help text for the page at positionindex totext.

This function was introduced in Qt 4.1.

See alsotabWhatsThis().

[virtual protected]void QTabWidget::showEvent(QShowEvent *)

Reimplemented fromQWidget::showEvent().

[virtual]QSize QTabWidget::sizeHint() const

Reimplemented fromQWidget::sizeHint().

[protected]QTabBar * QTabWidget::tabBar() const

Returns the currentQTabBar.

See alsosetTabBar().

[signal]void QTabWidget::tabCloseRequested(int index)

This signal is emitted when the close button on a tab is clicked. Theindex is the index that should be removed.

This function was introduced in Qt 4.5.

See alsosetTabsClosable().

QIcon QTabWidget::tabIcon(int index) const

Returns the icon for the tab on the page at positionindex.

See alsosetTabIcon().

[virtual protected]void QTabWidget::tabInserted(int index)

This virtual handler is called after a new tab was added or inserted at positionindex.

See alsotabRemoved().

[virtual protected]void QTabWidget::tabRemoved(int index)

This virtual handler is called after a tab was removed from positionindex.

See alsotabInserted().

QString QTabWidget::tabText(int index) const

Returns the label text for the tab on the page at positionindex.

See alsosetTabText().

QString QTabWidget::tabToolTip(int index) const

Returns the tab tool tip for the page at positionindex or an empty string if no tool tip has been set.

See alsosetTabToolTip().

QString QTabWidget::tabWhatsThis(int index) const

Returns the What's This help text for the page at positionindex, or an empty string if no help text has been set.

This function was introduced in Qt 4.1.

See alsosetTabWhatsThis().

QWidget * QTabWidget::widget(int index) const

Returns the tab page at index positionindex or 0 if theindex is out of range.

© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.


[8]ページ先頭

©2009-2025 Movatter.jp