Eneboo - Documentación para desarrolladores
|
The QTabBar class provides a tab bar, e.g. for use in tabbed dialogs. Más...
#include <qtabbar.h>
The QTabBar 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 predefined shapes, and emits a signal when a tab is selected. It can be subclassed to tailor the look and feel. Qt also provides a ready-made {QTabWidget} and a {QTabDialog}.
The choice of tab shape is a matter of taste, although tab dialogs (for preferences and similar) invariably use RoundedAbove
; nobody uses TriangularAbove
. Tab controls in windows other than dialogs almost always use either RoundedBelow
or TriangularBelow
. Many spreadsheets and other tab controls in which all the pages are essentially similar use TriangularBelow
, whereas RoundedBelow
is used mostly when the pages are different (e.g. a multi-page tool palette).
The most important part of QTabBar's API is the selected() signal. This is emitted whenever the selected page changes (even at startup, when the selected page changes from 'none'). There is also a slot, setCurrentTab(), which can be used to select a page programmatically.
QTabBar creates automatic accelerator keys in the manner of QButton; e.g. if a tab's label is "\&Graphics", Alt+G becomes an accelerator key for switching to that tab.
The following virtual functions may need to be reimplemented: paint() paints a single tab. paintEvent() calls paint() for each tab so that any overlap will look right. addTab() creates a new tab and adds it to the bar. selectTab() decides which tab, if any, the user selects with the mouse.
The index of the current tab is returned by currentTab(). The tab with a particular index is returned by tabAt(), the tab with a particular id is returned by tab(). The index of a tab is returned by indexOf(). The current tab can be set by index or tab pointer using one of the setCurrentTab() functions.
enum QTabBar::Shape |
This enum type lists the built-in shapes supported by QTabBar:
RoundedAbove the normal rounded look above the pages
RoundedBelow the normal rounded look below the pages
TriangularAbove triangular tabs above the pages (very unusual; included for completeness)
TriangularBelow triangular tabs similar to those used in the Excel spreadsheet, for example
enum QTabBar::Shape |
QTabBar::QTabBar | ( | QWidget * | parent = 0 , |
const char * | name = 0 |
||
) |
Constructs a new, empty tab bar; the parent and name arguments are passed on to the QWidget constructor.
QTabBar::~QTabBar | ( | ) |
Destroys the tab control, freeing memory used.
QTabBar::QTabBar | ( | QWidget * | parent = 0 , |
const char * | name = 0 |
||
) |
QTabBar::~QTabBar | ( | ) |
Adds the tab, newTab, to the tab control.
Sets newTab's id to a new id and places the tab just to the right of the existing tabs. If the tab's label contains an ampersand, the letter following the ampersand is used as an accelerator for the tab, e.g. if the label is "Bro\&wse" then Alt+W becomes an accelerator which will move the focus to this tab. Returns the id.
int QTabBar::count | ( | ) | const |
int QTabBar::count | ( | ) | const |
int QTabBar::currentTab | ( | ) | const |
int QTabBar::currentTab | ( | ) | const |
This is the main event handler; it handles event e. You can reimplement this function in a subclass, but we recommend using one of the specialized event handlers instead.
The main event handler first passes an event through all event filters that have been installed. If none of the filters intercept the event, it calls one of the specialized event handlers.
Key press and release events are treated differently from other events. event() checks for Tab and Shift+Tab and tries to move the focus appropriately. If there is no widget to move the focus to (or the key press is not Tab or Shift+Tab), event() calls keyPressEvent().
This function returns TRUE if it is able to pass the event over to someone (i.e. someone wanted the event); otherwise returns FALSE.
Reimplementado de QWidget.
void QTabBar::focusInEvent | ( | QFocusEvent * | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus received) for the widget.
A widget normally must setFocusPolicy() to something other than NoFocus
in order to receive focus events. (Note that the application programmer can call setFocus() on any widget, even those that do not normally accept focus.)
The default implementation updates the widget (except for toplevel widgets that do not specify a focusPolicy() ). It also calls setMicroFocusHint(), hinting any system-specific input tools about the focus of the user's attention.
Reimplementado de QWidget.
void QTabBar::focusInEvent | ( | QFocusEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
void QTabBar::focusOutEvent | ( | QFocusEvent * | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive keyboard focus events (focus lost) for the widget.
A widget normally must setFocusPolicy() to something other than NoFocus
in order to receive focus events. (Note that the application programmer can call setFocus() on any widget, even those that do not normally accept focus.)
The default implementation updates the widget (except for toplevel widgets that do not specify a focusPolicy() ). It also calls setMicroFocusHint(), hinting any system-specific input tools about the focus of the user's attention.
Reimplementado de QWidget.
void QTabBar::focusOutEvent | ( | QFocusEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
void QTabBar::fontChange | ( | const QFont & | oldFont | ) | [protected, virtual] |
This virtual function is called from setFont(). oldFont is the previous font; you can get the new font from font().
Reimplement this function if your widget needs to know when its font changes. You will almost certainly need to update the widget using update().
The default implementation updates the widget including its geometry.
Reimplementado de QWidget.
void QTabBar::fontChange | ( | const QFont & | oldFont | ) | [protected, virtual] |
This virtual function is called from setFont(). oldFont is the previous font; you can get the new font from font().
Reimplement this function if your widget needs to know when its font changes. You will almost certainly need to update the widget using update().
The default implementation updates the widget including its geometry.
Reimplementado de QWidget.
Returns the position index of the tab with id id or -1 if no tab has this id.
Inserts the tab, newTab, into the tab control.
If index is not specified, the tab is simply appended. Otherwise it's inserted at the specified position.
Sets newTab's id to a new id. If the tab's label contains an ampersand, the letter following the ampersand is used as an accelerator for the tab, e.g. if the label is "Bro\&wse" then Alt+W becomes an accelerator which will move the focus to this tab. Returns the id.
Returns TRUE if the tab with id id exists and is enabled; otherwise returns FALSE.
int QTabBar::keyboardFocusTab | ( | ) | const |
int QTabBar::keyboardFocusTab | ( | ) | const |
void QTabBar::keyPressEvent | ( | QKeyEvent * | e | ) | [protected, virtual] |
This event handler, for event e, can be reimplemented in a subclass to receive key press events for the widget.
A widget must call setFocusPolicy() to accept focus initially and have focus in order to receive a key press event.
If you reimplement this handler, it is very important that you explicitly ignore the event if you do not understand it, so that the widget's parent can interpret it; otherwise, the event will be implicitly accepted. Although top-level widgets are able to choose whether to accept or ignore unknown events because they have no parent widgets that could otherwise handle them, it is good practice to explicitly ignore events to make widgets as reusable as possible.
The default implementation closes popup widgets if the user presses Esc. Otherwise the event is ignored.
Reimplementado de QWidget.
void QTabBar::layoutChanged | ( | ) | [signal] |
void QTabBar::layoutChanged | ( | ) | [signal] |
QTabBar emits the signal whenever the layout of the tab bar has been recalculated, for example when the contents of a tab change.
void QTabBar::layoutTabs | ( | ) | [virtual] |
Lays out all existing tabs according to their label and their iconset.
virtual void QTabBar::layoutTabs | ( | ) | [virtual] |
void QTabBar::mouseMoveEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
void QTabBar::mouseMoveEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
This event handler, for event e, can be reimplemented in a subclass to receive mouse move events for the widget.
If mouse tracking is switched off, mouse move events only occur if a mouse button is pressed while the mouse is being moved. If mouse tracking is switched on, mouse move events occur even if no mouse button is pressed.
QMouseEvent::pos() reports the position of the mouse cursor, relative to this widget. For press and release events, the position is usually the same as the position of the last mouse move event, but it might be different if the user's hand shakes. This is a feature of the underlying window system, not Qt.
Reimplementado de QWidget.
void QTabBar::mousePressEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
void QTabBar::mousePressEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
This event handler, for event e, can be reimplemented in a subclass to receive mouse press events for the widget.
If you create new widgets in the mousePressEvent() the mouseReleaseEvent() may not end up where you expect, depending on the underlying window system (or X11 window manager), the widgets' location and maybe more.
The default implementation implements the closing of popup widgets when you click outside the window. For other widget types it does nothing.
Reimplementado de QWidget.
void QTabBar::mouseReleaseEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
Reimplementado de QWidget.
void QTabBar::mouseReleaseEvent | ( | QMouseEvent * | e | ) | [protected, virtual] |
This event handler, for event e, can be reimplemented in a subclass to receive mouse release events for the widget.
Reimplementado de QWidget.
Paints the tab t using painter p. If and only if selected is TRUE, t is drawn currently selected.
This virtual function may be reimplemented to change the look of QTabBar. If you decide to reimplement it, you may also need to reimplement sizeHint().
void QTabBar::paintEvent | ( | QPaintEvent * | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive paint events.
A paint event is a request to repaint all or part of the widget. It can happen as a result of repaint() or update(), or because the widget was obscured and has now been uncovered, or for many other reasons.
Many widgets can simply repaint their entire surface when asked to, but some slow widgets need to optimize by painting only the requested region: QPaintEvent::region(). This speed optimization does not change the result, as painting is clipped to that region during event processing. QListView and QCanvas do this, for example.
Qt also tries to speed up painting by merging multiple paint events into one. When update() is called several times or the window system sends several paint events, Qt merges these events into one event with a larger region (see QRegion::unite()). repaint() does not permit this optimization, so we suggest using update() when possible.
When the paint event occurs, the update region has normally been erased, so that you're painting on the widget's background. There are a couple of exceptions and QPaintEvent::erased() tells you whether the widget has been erased or not.
The background can be set using setBackgroundMode(), setPaletteBackgroundColor() or setBackgroundPixmap(). The documentation for setBackgroundMode() elaborates on the background; we recommend reading it.
Reimplementado de QWidget.
void QTabBar::paintEvent | ( | QPaintEvent * | e | ) | [protected, virtual] |
Repaints the tab row. All the painting is done by paint(); paintEvent() only decides which tabs need painting and in what order. The event is passed in e.
Reimplementado de QWidget.
virtual void QTabBar::paintLabel | ( | QPainter * | , |
const QRect & | , | ||
QTab * | , | ||
bool | |||
) | const [protected, virtual] |
void QTabBar::paintLabel | ( | QPainter * | p, |
const QRect & | br, | ||
QTab * | t, | ||
bool | has_focus | ||
) | const [protected, virtual] |
Paints the label of tab t centered in rectangle br using painter p. A focus indication is drawn if has_focus is TRUE.
virtual void QTabBar::removeTab | ( | QTab * | ) | [virtual] |
void QTabBar::removeTab | ( | QTab * | t | ) | [virtual] |
Removes tab t from the tab control, and deletes the tab.
void QTabBar::removeToolTip | ( | int | index | ) |
void QTabBar::removeToolTip | ( | int | index | ) |
Removes the tool tip for the tab at index position index.
void QTabBar::resizeEvent | ( | QResizeEvent * | ) | [protected, virtual] |
This event handler can be reimplemented in a subclass to receive widget resize events. When resizeEvent() is called, the widget already has its new geometry. The old size is accessible through QResizeEvent::oldSize().
The widget will be erased and receive a paint event immediately after processing the resize event. No drawing need be (or should be) done inside this handler.
Widgets that have been created with the WNoAutoErase
flag will not be erased. Nevertheless, they will receive a paint event for their entire area afterwards. Again, no drawing needs to be done inside this handler.
The default implementation calls updateMask() if the widget has automatic masking enabled.
Reimplementado de QWidget.
void QTabBar::resizeEvent | ( | QResizeEvent * | ) | [protected, virtual] |
Reimplementado de QWidget.
void QTabBar::selected | ( | int | ) | [signal] |
void QTabBar::selected | ( | int | id | ) | [signal] |
This virtual function is called by the mouse event handlers to determine which tab is pressed. The default implementation returns a pointer to the tab whose bounding rectangle contains p, if exactly one tab's bounding rectangle contains p. Otherwise it returns 0.
virtual void QTabBar::setCurrentTab | ( | QTab * | ) | [virtual, slot] |
void QTabBar::setCurrentTab | ( | int | id | ) | [virtual, slot] |
void QTabBar::setCurrentTab | ( | QTab * | tab | ) | [virtual, slot] |
Esta es una función miembro sobrecargada que se suministra por conveniencia. Difiere de la anterior función solamente en los argumentos que acepta. Raises tab and emits the selected() signal unless the tab was already current.
virtual void QTabBar::setCurrentTab | ( | int | ) | [virtual, slot] |
virtual void QTabBar::setShape | ( | Shape | ) | [virtual] |
void QTabBar::setShape | ( | Shape | s | ) | [virtual] |
Enables tab id if enabled is TRUE or disables it if enabled is FALSE. If id is currently selected, setTabEnabled(FALSE) makes another tab selected.
setTabEnabled() updates the display if this causes a change in id's status.
Sets the tool tip for the tab at index position index to tip.
Shape QTabBar::shape | ( | ) | const |
Shape QTabBar::shape | ( | ) | const |
void QTabBar::show | ( | ) | [virtual] |
Shows the widget and its child widgets.
If its size or position has changed, Qt guarantees that a widget gets move and resize events just before it is shown.
You almost never have to reimplement this function. If you need to change some settings before a widget is shown, use showEvent() instead. If you need to do some delayed initialization use polish().
Reimplementado de QWidget.
void QTabBar::show | ( | ) | [virtual] |
Reimplementado de QWidget.
void QTabBar::styleChange | ( | QStyle & | ) | [protected, virtual] |
This virtual function is called when the style of the widgets changes. oldStyle is the previous GUI style; you can get the new style from style().
Reimplement this function if your widget needs to know when its GUI style changes. You will almost certainly need to update the widget using update().
The default implementation updates the widget including its geometry.
Reimplementado de QWidget.
Returns the tab with id id or 0 if there is no such tab.
Returns the tool tip for the tab at index position index.
QTab [friend] |
QTabBarToolTip [friend] |
int QTabBar::currentTab [read, write] |
the id of the tab bar's visible tab
If no tab page is currently visible, the property's value is -1. Even if the property's value is not -1, you cannot assume that the user can see the relevant page, or that the tab is enabled. When you need to display something the value of this property represents the best page to display.
When this property is set to id, it will raise the tab with the id id and emit the selected() signal.
int QTabBar::keyboardFocusTab [read] |
the id of the tab that has the keyboard focus
This property contains the id of the tab that has the keyboard focus or -1 if the tab bar does not have the keyboard focus.
Shape QTabBar::shape [read, write] |
the shape of the tabs in the tab bar
The value of this property is one of the following: RoundedAbove
(default), RoundedBelow
, TriangularAbove
or TriangularBelow
.