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

QTabBar Class

TheQTabBar class provides a tab bar, e.g. for use in tabbed dialogs.More...

Header:#include <QTabBar>
Inherits:QWidget

Public Types

enumButtonPosition { LeftSide, RightSide }
enumSelectionBehavior { SelectLeftTab, SelectRightTab, SelectPreviousTab }
enumShape { RoundedNorth, RoundedSouth, RoundedWest, RoundedEast, ..., TriangularEast }

Properties

Public Functions

QTabBar(QWidget * parent = 0)
~QTabBar()
intaddTab(const QString & text)
intaddTab(const QIcon & icon, const QString & text)
intcount() const
intcurrentIndex() const
booldocumentMode() const
booldrawBase() const
Qt::TextElideModeelideMode() const
boolexpanding() const
QSizeiconSize() const
intinsertTab(int index, const QString & text)
intinsertTab(int index, const QIcon & icon, const QString & text)
boolisMovable() const
boolisTabEnabled(int index) const
voidmoveTab(int from, int to)
voidremoveTab(int index)
SelectionBehaviorselectionBehaviorOnRemove() const
voidsetDocumentMode(bool set)
voidsetDrawBase(bool drawTheBase)
voidsetElideMode(Qt::TextElideMode)
voidsetExpanding(bool enabled)
voidsetIconSize(const QSize & size)
voidsetMovable(bool movable)
voidsetSelectionBehaviorOnRemove(SelectionBehavior behavior)
voidsetShape(Shape shape)
voidsetTabButton(int index, ButtonPosition position, QWidget * widget)
voidsetTabData(int index, const QVariant & data)
voidsetTabEnabled(int index, bool enabled)
voidsetTabIcon(int index, const QIcon & icon)
voidsetTabText(int index, const QString & text)
voidsetTabTextColor(int index, const QColor & color)
voidsetTabToolTip(int index, const QString & tip)
voidsetTabWhatsThis(int index, const QString & text)
voidsetTabsClosable(bool closable)
voidsetUsesScrollButtons(bool useButtons)
Shapeshape() const
inttabAt(const QPoint & position) const
QWidget *tabButton(int index, ButtonPosition position) const
QVarianttabData(int index) const
QIcontabIcon(int index) const
QRecttabRect(int index) const
QStringtabText(int index) const
QColortabTextColor(int index) const
QStringtabToolTip(int index) const
QStringtabWhatsThis(int index) const
booltabsClosable() const
boolusesScrollButtons() const

Reimplemented Public Functions

virtual QSizeminimumSizeHint() const
virtual QSizesizeHint() const

Public Slots

voidsetCurrentIndex(int index)
  • 19 public slots inherited fromQWidget
  • 1 public slot inherited fromQObject

Signals

voidcurrentChanged(int index)
voidtabCloseRequested(int index)
voidtabMoved(int from, int to)

Protected Functions

voidinitStyleOption(QStyleOptionTab * option, int tabIndex) const
virtual voidtabInserted(int index)
virtual voidtabLayoutChange()
virtual voidtabRemoved(int index)
virtual QSizetabSizeHint(int index) const

Reimplemented Protected Functions

virtual voidchangeEvent(QEvent * event)
virtual boolevent(QEvent * event)
virtual voidhideEvent(QHideEvent *)
virtual voidkeyPressEvent(QKeyEvent * event)
virtual voidmouseMoveEvent(QMouseEvent * event)
virtual voidmousePressEvent(QMouseEvent * event)
virtual voidmouseReleaseEvent(QMouseEvent * event)
virtual voidpaintEvent(QPaintEvent *)
virtual voidresizeEvent(QResizeEvent *)
virtual voidshowEvent(QShowEvent *)
virtual voidwheelEvent(QWheelEvent * event)
  • 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

TheQTabBar class provides a tab bar, e.g. for use in tabbed dialogs.

QTabBar is straightforward to use; it draws the tabs using one of the predefinedshapes, and emits a signal when a tab is selected. It can be subclassed to tailor the look and feel. Qt also provides a ready-madeQTabWidget.

Each tab has atabText(), an optionaltabIcon(), an optionaltabToolTip(), optionaltabWhatsThis() and optionaltabData(). The tabs's attributes can be changed withsetTabText(),setTabIcon(),setTabToolTip(),setTabWhatsThis andsetTabData(). Each tabs can be enabled or disabled individually withsetTabEnabled().

Each tab can display text in a distinct color. The current text color for a tab can be found with thetabTextColor() function. Set the text color for a particular tab withsetTabTextColor().

Tabs are added usingaddTab(), or inserted at particular positions usinginsertTab(). The total number of tabs is given bycount(). Tabs can be removed from the tab bar withremoveTab(). CombiningremoveTab() andinsertTab() allows you to move tabs to different positions.

Theshape property defines the tabs' appearance. The choice of shape is a matter of taste, although tab dialogs (for preferences and similar) invariably useRoundedNorth. Tab controls in windows other than dialogs almost always use eitherRoundedSouth orTriangularSouth. Many spreadsheets and other tab controls in which all the pages are essentially similar useTriangularSouth, whereasRoundedSouth is used mostly when the pages are different (e.g. a multi-page tool palette). The default inQTabBar isRoundedNorth.

The most important part ofQTabBar's API is thecurrentChanged() signal. This is emitted whenever the current tab changes (even at startup, when the current tab changes from 'none'). There is also a slot,setCurrentIndex(), which can be used to select a tab programmatically. The functioncurrentIndex() returns the index of the current tab,count holds the number of tabs.

QTabBar creates automatic mnemonic keys in the manner ofQAbstractButton; e.g. if a tab's label is "&Graphics", Alt+G becomes a shortcut key for switching to that tab.

The following virtual functions may need to be reimplemented in order to tailor the look and feel or store extra data with each tab:

For subclasses, you might also need thetabRect() functions which returns the visual geometry of a single tab.

Screenshot of a Plastique style tab barA tab bar shown in the Plastique widget style.
Screenshot of a truncated Plastique tab barA truncated tab bar shown in the Plastique widget style.

See alsoQTabWidget.

Member Type Documentation

enum QTabBar::ButtonPosition

This enum type lists the location of the widget on a tab.

ConstantValueDescription
QTabBar::LeftSide0Left side of the tab.
QTabBar::RightSide1Right side of the tab.

This enum was introduced or modified in Qt 4.5.

enum QTabBar::SelectionBehavior

This enum type lists the behavior ofQTabBar when a tab is removed and the tab being removed is also the current tab.

ConstantValueDescription
QTabBar::SelectLeftTab0Select the tab to the left of the one being removed.
QTabBar::SelectRightTab1Select the tab to the right of the one being removed.
QTabBar::SelectPreviousTab2Select the previously selected tab.

This enum was introduced or modified in Qt 4.5.

enum QTabBar::Shape

This enum type lists the built-in shapes supported byQTabBar. Treat these as hints as some styles may not render some of the shapes. However, position should be honored.

ConstantValueDescription
QTabBar::RoundedNorth0The normal rounded look above the pages
QTabBar::RoundedSouth1The normal rounded look below the pages
QTabBar::RoundedWest2The normal rounded look on the left side of the pages
QTabBar::RoundedEast3The normal rounded look on the right side the pages
QTabBar::TriangularNorth4Triangular tabs above the pages.
QTabBar::TriangularSouth5Triangular tabs similar to those used in the Excel spreadsheet, for example
QTabBar::TriangularWest6Triangular tabs on the left of the pages.
QTabBar::TriangularEast7Triangular tabs on the right of the pages.

Property Documentation

count : constint

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

Access functions:

intcount() const

currentIndex :int

This property holds the index of the tab bar's visible tab.

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

Access functions:

intcurrentIndex() const
voidsetCurrentIndex(int index)

Notifier signal:

voidcurrentChanged(int index)

documentMode :bool

This property holds whether or not the tab bar is rendered in a mode suitable for the main window.

This property is used as a hint for styles to draw the tabs in a different way then they would normally look in a tab widget. On Mac OS X this will look similar to the tabs in Safari or Leopard's Terminal.app.

This property was introduced in Qt 4.5.

Access functions:

booldocumentMode() const
voidsetDocumentMode(bool set)

See alsoQTabWidget::documentMode.

drawBase :bool

This property defines whether or not tab bar should draw its base.

If true thenQTabBar draws a base in relation to the styles overlab. Otherwise only the tabs are drawn.

Access functions:

booldrawBase() const
voidsetDrawBase(bool drawTheBase)

See alsoQStyle::pixelMetric(),QStyle::PM_TabBarBaseOverlap, andQStyleOptionTabBarBaseV2.

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 dependent.

This property was introduced in Qt 4.2.

Access functions:

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

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

expanding :bool

This property holds when expanding is true QTabBar will expand the tabs to use the empty space.

By default the value is true.

This property was introduced in Qt 4.5.

Access functions:

boolexpanding() const
voidsetExpanding(bool enabled)

See alsoQTabWidget::documentMode.

iconSize :QSize

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

The default value is style-dependent.iconSize is a maximum size; icons that are smaller are not scaled up.

This property was introduced in Qt 4.1.

Access functions:

QSizeiconSize() const
voidsetIconSize(const QSize & size)

See alsoQTabWidget::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)

selectionBehaviorOnRemove :SelectionBehavior

This property holds what tab should be set as current when removeTab is called if the removed tab is also the current tab.

By default the value isSelectRightTab.

This property was introduced in Qt 4.5.

Access functions:

SelectionBehaviorselectionBehaviorOnRemove() const
voidsetSelectionBehaviorOnRemove(SelectionBehavior behavior)

See alsoremoveTab().

shape :Shape

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

Possible values for this property are described by the Shape enum.

Access functions:

Shapeshape() const
voidsetShape(Shape shape)

tabsClosable :bool

This property holds whether or not a tab bar should place close buttons on each tab.

When tabsClosable is set to true a close button will appear on the tab on either the left or right hand side depending upon the style. When the button is clicked the tab the signaltabCloseRequested will be emitted.

By default the value is false.

This property was introduced in Qt 4.5.

Access functions:

booltabsClosable() const
voidsetTabsClosable(bool closable)

See alsosetTabButton() andtabRemoved().

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,QTabWidget::usesScrollButtons, andQStyle::SH_TabBar_PreferNoArrows.

Member Function Documentation

QTabBar::QTabBar(QWidget * parent = 0)

Creates a new tab bar with the givenparent.

QTabBar::~QTabBar()

Destroys the tab bar.

int QTabBar::addTab(constQString & text)

Adds a new tab with texttext. Returns the new tab's index.

int QTabBar::addTab(constQIcon & icon, constQString & text)

This is an overloaded function.

Adds a new tab with iconicon and texttext. Returns the new tab's index.

[virtual protected]void QTabBar::changeEvent(QEvent * event)

Reimplemented fromQWidget::changeEvent().

[virtual protected]bool QTabBar::event(QEvent * event)

Reimplemented fromQObject::event().

[virtual protected]void QTabBar::hideEvent(QHideEvent *)

Reimplemented fromQWidget::hideEvent().

[protected]void QTabBar::initStyleOption(QStyleOptionTab * option,int tabIndex) const

Initializeoption with the values from the tab attabIndex. This method is useful for subclasses when they need aQStyleOptionTab,QStyleOptionTabV2, orQStyleOptionTabV3 but don't want to fill in all the information themselves. This function will check the version of theQStyleOptionTab and fill in the additional values for aQStyleOptionTabV2 andQStyleOptionTabV3.

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

int QTabBar::insertTab(int index, constQString & text)

Inserts a new tab with texttext at positionindex. Ifindex is out of range, the new tab is appened. Returns the new tab's index.

int QTabBar::insertTab(int index, constQIcon & icon, constQString & text)

This is an overloaded function.

Inserts a new tab with iconicon and texttext at positionindex. Ifindex is out of range, the new tab is appended. Returns the new tab's index.

If theQTabBar was empty before this function is called, the inserted tab becomes the current tab.

Inserting a new tab at an index less than or equal to the current index will increment the current index, but keep the current tab.

bool QTabBar::isTabEnabled(int index) const

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

[virtual protected]void QTabBar::keyPressEvent(QKeyEvent * event)

Reimplemented fromQWidget::keyPressEvent().

[virtual]QSize QTabBar::minimumSizeHint() const

Reimplemented fromQWidget::minimumSizeHint().

[virtual protected]void QTabBar::mouseMoveEvent(QMouseEvent * event)

Reimplemented fromQWidget::mouseMoveEvent().

[virtual protected]void QTabBar::mousePressEvent(QMouseEvent * event)

Reimplemented fromQWidget::mousePressEvent().

[virtual protected]void QTabBar::mouseReleaseEvent(QMouseEvent * event)

Reimplemented fromQWidget::mouseReleaseEvent().

void QTabBar::moveTab(int from,int to)

Moves the item at index positionfrom to index positionto.

This function was introduced in Qt 4.5.

See alsotabMoved() andtabLayoutChange().

[virtual protected]void QTabBar::paintEvent(QPaintEvent *)

Reimplemented fromQWidget::paintEvent().

void QTabBar::removeTab(int index)

Removes the tab at positionindex.

See alsoSelectionBehavior.

[virtual protected]void QTabBar::resizeEvent(QResizeEvent *)

Reimplemented fromQWidget::resizeEvent().

void QTabBar::setTabButton(int index,ButtonPosition position,QWidget * widget)

Setswidget on the tabindex. The widget is placed on the left or right hand side depending upon theposition.

Any previously set widget inposition is hidden.

The tab bar will take ownership of the widget and so all widgets set here will be deleted by the tab bar when it is destroyed unless you separately reparent the widget after setting some other widget (or 0).

This function was introduced in Qt 4.5.

See alsotabButton() andtabsClosable().

void QTabBar::setTabData(int index, constQVariant & data)

Sets the data of the tab at positionindex todata.

See alsotabData().

void QTabBar::setTabEnabled(int index,bool enabled)

Ifenabled is true then the tab at positionindex is enabled; otherwise the item at positionindex is disabled.

See alsoisTabEnabled().

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

Sets the icon of the tab at positionindex toicon.

See alsotabIcon().

void QTabBar::setTabText(int index, constQString & text)

Sets the text of the tab at positionindex totext.

See alsotabText().

void QTabBar::setTabTextColor(int index, constQColor & color)

Sets the color of the text in the tab with the givenindex to the specifiedcolor.

If an invalid color is specified, the tab will use theQTabBar foreground role instead.

See alsotabTextColor().

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

Sets the tool tip of the tab at positionindex totip.

See alsotabToolTip().

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

Sets the What's This help text of the tab at positionindex totext.

This function was introduced in Qt 4.1.

See alsotabWhatsThis().

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

Reimplemented fromQWidget::showEvent().

[virtual]QSize QTabBar::sizeHint() const

Reimplemented fromQWidget::sizeHint().

int QTabBar::tabAt(constQPoint & position) const

Returns the index of the tab that coversposition or -1 if no tab coversposition;

This function was introduced in Qt 4.3.

QWidget * QTabBar::tabButton(int index,ButtonPosition position) const

Returns the widget set a tabindex andposition or 0 if one is not set.

See alsosetTabButton().

[signal]void QTabBar::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().

QVariant QTabBar::tabData(int index) const

Returns the data of the tab at positionindex, or a null variant ifindex is out of range.

See alsosetTabData().

QIcon QTabBar::tabIcon(int index) const

Returns the icon of the tab at positionindex, or a null icon ifindex is out of range.

See alsosetTabIcon().

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

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

See alsotabRemoved().

[virtual protected]void QTabBar::tabLayoutChange()

This virtual handler is called whenever the tab layout changes.

See alsotabRect().

[signal]void QTabBar::tabMoved(int from,int to)

This signal is emitted when the tab has moved the tab at index positionfrom to index positionto.

note:QTabWidget will automatically move the page when this signal is emitted from its tab bar.

This function was introduced in Qt 4.5.

See alsomoveTab().

QRect QTabBar::tabRect(int index) const

Returns the visual rectangle of the tab at positionindex, or a null rectangle ifindex is out of range.

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

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

See alsotabInserted().

[virtual protected]QSize QTabBar::tabSizeHint(int index) const

Returns the size hint for the tab at positionindex.

QString QTabBar::tabText(int index) const

Returns the text of the tab at positionindex, or an empty string ifindex is out of range.

See alsosetTabText().

QColor QTabBar::tabTextColor(int index) const

Returns the text color of the tab with the givenindex, or a invalid color ifindex is out of range.

See alsosetTabTextColor().

QString QTabBar::tabToolTip(int index) const

Returns the tool tip of the tab at positionindex, or an empty string ifindex is out of range.

See alsosetTabToolTip().

QString QTabBar::tabWhatsThis(int index) const

Returns the What's This help text of the tab at positionindex, or an empty string ifindex is out of range.

This function was introduced in Qt 4.1.

See alsosetTabWhatsThis().

[virtual protected]void QTabBar::wheelEvent(QWheelEvent * event)

Reimplemented fromQWidget::wheelEvent().

© 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