Qt 4.8
qtabwidget.h
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
4 ** Contact: http://www.qt-project.org/legal
5 **
6 ** This file is part of the QtGui module of the Qt Toolkit.
7 **
8 ** $QT_BEGIN_LICENSE:LGPL$
9 ** Commercial License Usage
10 ** Licensees holding valid commercial Qt licenses may use this file in
11 ** accordance with the commercial license agreement provided with the
12 ** Software or, alternatively, in accordance with the terms contained in
13 ** a written agreement between you and Digia. For licensing terms and
14 ** conditions see http://qt.digia.com/licensing. For further information
15 ** use the contact form at http://qt.digia.com/contact-us.
16 **
17 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Digia gives you certain additional
26 ** rights. These rights are described in the Digia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** GNU General Public License Usage
30 ** Alternatively, this file may be used under the terms of the GNU
31 ** General Public License version 3.0 as published by the Free Software
32 ** Foundation and appearing in the file LICENSE.GPL included in the
33 ** packaging of this file. Please review the following information to
34 ** ensure the GNU General Public License version 3.0 requirements will be
35 ** met: http://www.gnu.org/copyleft/gpl.html.
36 **
37 **
38 ** $QT_END_LICENSE$
39 **
40 ****************************************************************************/
41 
42 #ifndef QTABWIDGET_H
43 #define QTABWIDGET_H
44 
45 #include <QtGui/qwidget.h>
46 #include <QtGui/qicon.h>
47 
49 
51 
52 QT_MODULE(Gui)
53 
54 #ifndef QT_NO_TABWIDGET
55 
56 class QTabBar;
57 class QTabWidgetPrivate;
59 
61 {
62  Q_OBJECT
64  TabPosition tabPosition;
65  TabShape tabShape;
66  int currentIndex;
67  int count;
68  QSize iconSize;
69  Qt::TextElideMode elideMode;
70  bool usesScrollButtons;
71  bool documentMode;
72  bool tabsClosable;
73  bool movable;
74 
75 public:
76  explicit QTabWidget(QWidget *parent = 0);
77  ~QTabWidget();
78 
79  int addTab(QWidget *widget, const QString &);
80  int addTab(QWidget *widget, const QIcon& icon, const QString &label);
81 
82  int insertTab(int index, QWidget *widget, const QString &);
83  int insertTab(int index, QWidget *widget, const QIcon& icon, const QString &label);
84 
85  void removeTab(int index);
86 
87  bool isTabEnabled(int index) const;
88  void setTabEnabled(int index, bool);
89 
90  QString tabText(int index) const;
91  void setTabText(int index, const QString &);
92 
93  QIcon tabIcon(int index) const;
94  void setTabIcon(int index, const QIcon & icon);
95 
96 #ifndef QT_NO_TOOLTIP
97  void setTabToolTip(int index, const QString & tip);
98  QString tabToolTip(int index) const;
99 #endif
100 
101 #ifndef QT_NO_WHATSTHIS
102  void setTabWhatsThis(int index, const QString &text);
103  QString tabWhatsThis(int index) const;
104 #endif
105 
106  int currentIndex() const;
107  QWidget *currentWidget() const;
108  QWidget *widget(int index) const;
109  int indexOf(QWidget *widget) const;
110  int count() const;
111 
112  enum TabPosition { North, South, West, East
113 #if defined(QT3_SUPPORT) && !defined(Q_MOC_RUN)
114  , Top = North, Bottom = South
115 #endif
116  };
117  TabPosition tabPosition() const;
118  void setTabPosition(TabPosition);
119 
120  bool tabsClosable() const;
121  void setTabsClosable(bool closeable);
122 
123  bool isMovable() const;
124  void setMovable(bool movable);
125 
126  enum TabShape { Rounded, Triangular };
127  TabShape tabShape() const;
128  void setTabShape(TabShape s);
129 
130  QSize sizeHint() const;
131  QSize minimumSizeHint() const;
132  int heightForWidth(int width) const;
133 
134  void setCornerWidget(QWidget * w, Qt::Corner corner = Qt::TopRightCorner);
135  QWidget * cornerWidget(Qt::Corner corner = Qt::TopRightCorner) const;
136 
137  Qt::TextElideMode elideMode() const;
138  void setElideMode(Qt::TextElideMode);
139 
140  QSize iconSize() const;
141  void setIconSize(const QSize &size);
142 
143  bool usesScrollButtons() const;
144  void setUsesScrollButtons(bool useButtons);
145 
146  bool documentMode() const;
147  void setDocumentMode(bool set);
148 
149  void clear();
150 
151 public Q_SLOTS:
152  void setCurrentIndex(int index);
153  void setCurrentWidget(QWidget *widget);
154 
155 Q_SIGNALS:
156  void currentChanged(int index);
157  void tabCloseRequested(int index);
158 
159 protected:
160  virtual void tabInserted(int index);
161  virtual void tabRemoved(int index);
162 
163  void showEvent(QShowEvent *);
164  void resizeEvent(QResizeEvent *);
165  void keyPressEvent(QKeyEvent *);
166  void paintEvent(QPaintEvent *);
167  void setTabBar(QTabBar *);
168  QTabBar* tabBar() const;
169  void changeEvent(QEvent *);
170  bool event(QEvent *);
171  void initStyleOption(QStyleOptionTabWidgetFrame *option) const;
172 
173 public:
174 #ifdef QT3_SUPPORT
175  QT3_SUPPORT_CONSTRUCTOR QTabWidget(QWidget *parent, const char *name, Qt::WindowFlags f = 0);
176 
177  inline QT3_SUPPORT void insertTab(QWidget * w, const QString &s, int index = -1) { insertTab(index, w, s); }
178  inline QT3_SUPPORT void insertTab(QWidget *child, const QIcon& icon,
179  const QString &label, int index = -1) { insertTab(index, child, icon, label); }
180 
181  inline QT3_SUPPORT void changeTab(QWidget *w, const QString &s) {setTabText(indexOf(w), s); }
182  inline QT3_SUPPORT void changeTab(QWidget *w, const QIcon& icon,
183  const QString &label) { int idx = indexOf(w); setTabText(idx, label); setTabIcon(idx, icon); }
184 
185  inline QT3_SUPPORT bool isTabEnabled( QWidget *w) const {return isTabEnabled(indexOf(w)); }
186  inline QT3_SUPPORT void setTabEnabled(QWidget *w, bool b) { setTabEnabled(indexOf(w), b); }
187 
188  inline QT3_SUPPORT QString tabLabel(QWidget *w) const {return tabText(indexOf(w)); }
189  inline QT3_SUPPORT void setTabLabel(QWidget *w, const QString &l) { setTabText(indexOf(w), l); }
190 
191  inline QT3_SUPPORT QIcon tabIconSet(QWidget * w) const {return tabIcon(indexOf(w)); }
192  inline QT3_SUPPORT void setTabIconSet(QWidget * w, const QIcon & icon) { setTabIcon(indexOf(w), icon); }
193 
194  inline QT3_SUPPORT void removeTabToolTip(QWidget * w) {
195 #ifndef QT_NO_TOOLTIP
196  setTabToolTip(indexOf(w), QString());
197 #else
198  Q_UNUSED(w);
199 #endif
200  }
201  inline QT3_SUPPORT void setTabToolTip(QWidget * w, const QString & tip) {
202 #ifndef QT_NO_TOOLTIP
203  setTabToolTip(indexOf(w), tip);
204 #else
205  Q_UNUSED(w);
206  Q_UNUSED(tip);
207 #endif
208  }
209 
210  inline QT3_SUPPORT QString tabToolTip(QWidget * w) const {
211 #ifndef QT_NO_TOOLTIP
212  return tabToolTip(indexOf(w));
213 #else
214  Q_UNUSED(w);
215  return QString();
216 #endif
217  }
218 
219  inline QT3_SUPPORT QWidget * currentPage() const { return currentWidget(); }
220  inline QT3_SUPPORT QWidget *page(int index) const { return widget(index); }
221  inline QT3_SUPPORT QString label(int index) const { return tabText(index); }
222  inline QT3_SUPPORT int currentPageIndex() const { return currentIndex(); }
223 
224  inline QT3_SUPPORT int margin() const { return 0; }
225  inline QT3_SUPPORT void setMargin(int) {}
226 
227 public Q_SLOTS:
228  inline QT_MOC_COMPAT void setCurrentPage(int index) { setCurrentIndex(index); }
229  inline QT_MOC_COMPAT void showPage(QWidget *w) { setCurrentIndex(indexOf(w)); }
230  inline QT_MOC_COMPAT void removePage(QWidget *w) { removeTab(indexOf(w)); }
231 
232 Q_SIGNALS:
233  QT_MOC_COMPAT void currentChanged(QWidget *);
234  QT_MOC_COMPAT void selected(const QString&);
235 #endif // QT3_SUPPORT
236 
237 private:
238  Q_DECLARE_PRIVATE(QTabWidget)
239  Q_DISABLE_COPY(QTabWidget)
240  Q_PRIVATE_SLOT(d_func(), void _q_showTab(int))
241  Q_PRIVATE_SLOT(d_func(), void _q_removeTab(int))
242  Q_PRIVATE_SLOT(d_func(), void _q_tabMoved(int, int))
243  void setUpLayout(bool = false);
244  friend class Q3TabDialog;
245 };
246 
247 #endif // QT_NO_TABWIDGET
248 
250 
252 
253 #endif // QTABWIDGET_H
#define QT_MOC_COMPAT
Definition: qglobal.h:1128
The QKeyEvent class describes a key event.
Definition: qevent.h:224
virtual void showEvent(QShowEvent *)
This event handler can be reimplemented in a subclass to receive widget show events which are passed ...
Definition: qwidget.cpp:9842
virtual int heightForWidth(int) const
Returns the preferred height for this widget, given the width w.
Definition: qwidget.cpp:10241
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
QPointer< QWidget > widget
#define QT_MODULE(x)
Definition: qglobal.h:2783
virtual QSize minimumSizeHint() const
#define QT_BEGIN_HEADER
Definition: qglobal.h:136
TabPosition
This enum type defines where QTabWidget draws the tab row:
Definition: qtabwidget.h:112
#define Q_GUI_EXPORT
Definition: qglobal.h:1450
TextElideMode
Definition: qnamespace.h:263
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
static void clear(QVariant::Private *d)
Definition: qvariant.cpp:197
virtual void resizeEvent(QResizeEvent *)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition: qwidget.cpp:9587
#define Q_DISABLE_COPY(Class)
Disables the use of copy constructors and assignment operators for the given Class.
Definition: qglobal.h:2523
#define Q_PRIVATE_SLOT(d, signature)
Definition: qobjectdefs.h:73
The QTabBar class provides a tab bar, e.g.
Definition: qtabbar.h:59
#define Q_SLOTS
Definition: qobjectdefs.h:71
The QString class provides a Unicode character string.
Definition: qstring.h:83
#define Q_SIGNALS
Definition: qobjectdefs.h:72
virtual QSize sizeHint() const
#define Q_ENUMS(x)
Definition: qobjectdefs.h:84
virtual void paintEvent(QPaintEvent *)
This event handler can be reimplemented in a subclass to receive paint events passed in event...
Definition: qwidget.cpp:9548
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
const char * name
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
The QStyleOptionTabWidgetFrame class is used to describe the parameters for drawing the frame around ...
Definition: qstyleoption.h:175
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
virtual void keyPressEvent(QKeyEvent *)
This event handler, for event event, can be reimplemented in a subclass to receive key press events f...
Definition: qwidget.cpp:9375
#define Q_OBJECT
Definition: qobjectdefs.h:157
Corner
Definition: qnamespace.h:1456
Definition: qnamespace.h:54
QFactoryLoader * l
quint16 index
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
#define Q_DECLARE_PRIVATE(Class)
Definition: qglobal.h:2467
The QTabWidget class provides a stack of tabbed widgets.
Definition: qtabwidget.h:60
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
#define QT_END_HEADER
Definition: qglobal.h:137
#define Q_UNUSED(x)
Indicates to the compiler that the parameter with the specified name is not used in the body of a fun...
Definition: qglobal.h:1729
TabShape
This enum type defines the shape of the tabs:
Definition: qtabwidget.h:126
#define text
Definition: qobjectdefs.h:80
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60