Qt 4.8
qtabwidget.cpp
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 #include "qtabwidget.h"
43 
44 #ifndef QT_NO_TABWIDGET
45 #include "private/qwidget_p.h"
46 #include "private/qtabbar_p.h"
47 #include "qapplication.h"
48 #include "qbitmap.h"
49 #include "qdesktopwidget.h"
50 #include "qevent.h"
51 #include "qlayout.h"
52 #include "qstackedwidget.h"
53 #include "qstyle.h"
54 #include "qstyleoption.h"
55 #include "qstylepainter.h"
56 #include "qtabbar.h"
57 #include "qtoolbutton.h"
58 
60 
205 {
207 
208 public:
211  void updateTabBarPosition();
212  void _q_showTab(int);
213  void _q_removeTab(int);
214  void _q_tabMoved(int from, int to);
215  void init();
216  bool hasHeightForWidth() const;
217 
221  bool dirty;
227 };
228 
230  : tabs(0), stack(0), dirty(true),
231  pos(QTabWidget::North), shape(QTabWidget::Rounded),
233 {}
234 
236 {}
237 
239 {
240  Q_Q(QTabWidget);
241 
242  stack = new QStackedWidget(q);
243  stack->setObjectName(QLatin1String("qt_tabwidget_stackedwidget"));
244  stack->setLineWidth(0);
245  // hack so that QMacStyle::layoutSpacing() can detect tab widget pages
247 
248  QObject::connect(stack, SIGNAL(widgetRemoved(int)), q, SLOT(_q_removeTab(int)));
249  QTabBar *tabBar = new QTabBar(q);
250  tabBar->setObjectName(QLatin1String("qt_tabwidget_tabbar"));
251  tabBar->setDrawBase(false);
252  q->setTabBar(tabBar);
253 
256 #ifdef QT_KEYPAD_NAVIGATION
257  if (QApplication::keypadNavigationEnabled())
258  q->setFocusPolicy(Qt::NoFocus);
259  else
260 #endif
261  q->setFocusPolicy(Qt::TabFocus);
262  q->setFocusProxy(tabs);
263  q->setTabPosition(static_cast<QTabWidget::TabPosition> (q->style()->styleHint(
265 
266 }
267 
269 {
270  bool has = size_policy.hasHeightForWidth();
271  if (!has && stack)
273  return has;
274 }
275 
276 
285 {
286  if (!option)
287  return;
288 
289  Q_D(const QTabWidget);
290  option->initFrom(this);
291 
292  if (documentMode())
293  option->lineWidth = 0;
294  else
295  option->lineWidth = style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, this);
296 
297  int exth = style()->pixelMetric(QStyle::PM_TabBarBaseHeight, 0, this);
298  QSize t(0, d->stack->frameWidth());
299  if (d->tabs->isVisibleTo(const_cast<QTabWidget *>(this))) {
300  t = d->tabs->sizeHint();
301  if (documentMode()) {
302  if (tabPosition() == East || tabPosition() == West) {
303  t.setHeight(height());
304  } else {
305  t.setWidth(width());
306  }
307  }
308  }
309 
310  if (d->rightCornerWidget) {
311  const QSize rightCornerSizeHint = d->rightCornerWidget->sizeHint();
312  const QSize bounds(rightCornerSizeHint.width(), t.height() - exth);
313  option->rightCornerWidgetSize = rightCornerSizeHint.boundedTo(bounds);
314  } else {
315  option->rightCornerWidgetSize = QSize(0, 0);
316  }
317 
318  if (d->leftCornerWidget) {
319  const QSize leftCornerSizeHint = d->leftCornerWidget->sizeHint();
320  const QSize bounds(leftCornerSizeHint.width(), t.height() - exth);
321  option->leftCornerWidgetSize = leftCornerSizeHint.boundedTo(bounds);
322  } else {
323  option->leftCornerWidgetSize = QSize(0, 0);
324  }
325 
326  switch (d->pos) {
327  case QTabWidget::North:
328  option->shape = d->shape == QTabWidget::Rounded ? QTabBar::RoundedNorth
330  break;
331  case QTabWidget::South:
332  option->shape = d->shape == QTabWidget::Rounded ? QTabBar::RoundedSouth
334  break;
335  case QTabWidget::West:
336  option->shape = d->shape == QTabWidget::Rounded ? QTabBar::RoundedWest
338  break;
339  case QTabWidget::East:
340  option->shape = d->shape == QTabWidget::Rounded ? QTabBar::RoundedEast
342  break;
343  }
344 
345  option->tabBarSize = t;
346 
347  if (QStyleOptionTabWidgetFrameV2 *tabframe = qstyleoption_cast<QStyleOptionTabWidgetFrameV2*>(option)) {
348  QRect tbRect = tabBar()->geometry();
349  QRect selectedTabRect = tabBar()->tabRect(tabBar()->currentIndex());
350  tabframe->tabBarRect = tbRect;
351  selectedTabRect.moveTopLeft(selectedTabRect.topLeft() + tbRect.topLeft());
352  tabframe->selectedTabRect = selectedTabRect;
353  }
354 }
355 
360  : QWidget(*new QTabWidgetPrivate, parent, 0)
361 {
362  Q_D(QTabWidget);
363  d->init();
364 }
365 
366 #ifdef QT3_SUPPORT
367 
371 QTabWidget::QTabWidget(QWidget *parent, const char *name, Qt::WindowFlags f)
372  : QWidget(*new QTabWidgetPrivate, parent, f)
373 {
374  Q_D(QTabWidget);
376  d->init();
377 }
378 #endif
379 
384 {
385 }
386 
407 int QTabWidget::addTab(QWidget *child, const QString &label)
408 {
409  return insertTab(-1, child, label);
410 }
411 
412 
423 int QTabWidget::addTab(QWidget *child, const QIcon& icon, const QString &label)
424 {
425  return insertTab(-1, child, icon, label);
426 }
427 
428 
461 int QTabWidget::insertTab(int index, QWidget *w, const QString &label)
462 {
463  return insertTab(index, w, QIcon(), label);
464 }
465 
466 
478 int QTabWidget::insertTab(int index, QWidget *w, const QIcon& icon, const QString &label)
479 {
480  Q_D(QTabWidget);
481  if(!w)
482  return -1;
483  index = d->stack->insertWidget(index, w);
484  d->tabs->insertTab(index, icon, label);
485  setUpLayout();
486  tabInserted(index);
487 
488  return index;
489 }
490 
491 
504 void QTabWidget::setTabText(int index, const QString &label)
505 {
506  Q_D(QTabWidget);
507  d->tabs->setTabText(index, label);
508  setUpLayout();
509 }
510 
516 {
517  Q_D(const QTabWidget);
518  return d->tabs->tabText(index);
519 }
520 
529 void QTabWidget::setTabIcon(int index, const QIcon &icon)
530 {
531  Q_D(QTabWidget);
532  d->tabs->setTabIcon(index, icon);
533  setUpLayout();
534 }
535 
541 {
542  Q_D(const QTabWidget);
543  return d->tabs->tabIcon(index);
544 }
545 
553 {
554  Q_D(const QTabWidget);
555  return d->tabs->isTabEnabled(index);
556 }
557 
572 void QTabWidget::setTabEnabled(int index, bool enable)
573 {
574  Q_D(QTabWidget);
575  d->tabs->setTabEnabled(index, enable);
576  if (QWidget *widget = d->stack->widget(index))
577  widget->setEnabled(enable);
578 }
579 
603 {
604  Q_D(QTabWidget);
605  if (widget && widget->parentWidget() != this)
606  widget->setParent(this);
607 
608  if (corner & Qt::TopRightCorner) {
609  if (d->rightCornerWidget)
610  d->rightCornerWidget->hide();
611  d->rightCornerWidget = widget;
612  } else {
613  if (d->leftCornerWidget)
614  d->leftCornerWidget->hide();
615  d->leftCornerWidget = widget;
616  }
617  setUpLayout();
618 }
619 
624 {
625  Q_D(const QTabWidget);
626  if (corner & Qt::TopRightCorner)
627  return d->rightCornerWidget;
628  return d->leftCornerWidget;
629 }
630 
638 {
639  Q_D(QTabWidget);
640  if (QWidget *w = d->stack->widget(index))
641  d->stack->removeWidget(w);
642 }
643 
653 {
654  Q_D(const QTabWidget);
655  return d->stack->currentWidget();
656 }
657 
665 {
666  Q_D(const QTabWidget);
667  d->tabs->setCurrentIndex(indexOf(widget));
668 }
669 
670 
684 int QTabWidget::currentIndex() const
685 {
686  Q_D(const QTabWidget);
687  return d->tabs->currentIndex();
688 }
689 
691 {
692  Q_D(QTabWidget);
693  d->tabs->setCurrentIndex(index);
694 }
695 
696 
702 {
703  Q_D(const QTabWidget);
704  return d->stack->indexOf(w);
705 }
706 
707 
712 {
714  setUpLayout();
715 }
716 
725 {
726  Q_D(QTabWidget);
727  Q_ASSERT(tb);
728 
729  if (tb->parentWidget() != this) {
730  tb->setParent(this);
731  tb->show();
732  }
733  delete d->tabs;
734  d->tabs = tb;
735  setFocusProxy(d->tabs);
736  connect(d->tabs, SIGNAL(currentChanged(int)),
737  this, SLOT(_q_showTab(int)));
738  connect(d->tabs, SIGNAL(tabMoved(int,int)),
739  this, SLOT(_q_tabMoved(int,int)));
740  if (d->tabs->tabsClosable())
741  connect(d->tabs, SIGNAL(tabCloseRequested(int)),
742  this, SIGNAL(tabCloseRequested(int)));
743  tb->setExpanding(!documentMode());
744  setUpLayout();
745 }
746 
747 
754 {
755  Q_D(const QTabWidget);
756  return d->tabs;
757 }
758 
765 {
766  Q_Q(QTabWidget);
767  if (index < stack->count() && index >= 0)
768  stack->setCurrentIndex(index);
769  emit q->currentChanged(index);
770 #ifdef QT3_SUPPORT
771  emit q->selected(q->tabText(index));
772  emit q->currentChanged(stack->widget(index));
773 #endif
774 }
775 
777 {
778  Q_Q(QTabWidget);
779  tabs->removeTab(index);
780  q->setUpLayout();
781  q->tabRemoved(index);
782 }
783 
784 void QTabWidgetPrivate::_q_tabMoved(int from, int to)
785 {
786  stack->blockSignals(true);
787  QWidget *w = stack->widget(from);
788  stack->removeWidget(w);
789  stack->insertWidget(to, w);
790  stack->blockSignals(false);
791 }
792 
793 /*
794  Set up the layout.
795  Get subrect from the current style, and set the geometry for the
796  stack widget, tab bar and corner widgets.
797 */
798 void QTabWidget::setUpLayout(bool onlyCheck)
799 {
800  Q_D(QTabWidget);
801  if (onlyCheck && !d->dirty)
802  return; // nothing to do
803 
805  initStyleOption(&option);
806 
807  // this must be done immediately, because QWidgetItem relies on it (even if !isVisible())
808  d->setLayoutItemMargins(QStyle::SE_TabWidgetLayoutItem, &option);
809 
810  if (!isVisible()) {
811  d->dirty = true;
812  return; // we'll do it later
813  }
814 
815  QRect tabRect = style()->subElementRect(QStyle::SE_TabWidgetTabBar, &option, this);
816  d->panelRect = style()->subElementRect(QStyle::SE_TabWidgetTabPane, &option, this);
818  QRect leftCornerRect = style()->subElementRect(QStyle::SE_TabWidgetLeftCorner, &option, this);
819  QRect rightCornerRect = style()->subElementRect(QStyle::SE_TabWidgetRightCorner, &option, this);
820 
821  d->tabs->setGeometry(tabRect);
822  d->stack->setGeometry(contentsRect);
823  if (d->leftCornerWidget)
824  d->leftCornerWidget->setGeometry(leftCornerRect);
825  if (d->rightCornerWidget)
826  d->rightCornerWidget->setGeometry(rightCornerRect);
827 
828  if (!onlyCheck)
829  update();
830  updateGeometry();
831 }
832 
836 static inline QSize basicSize(
837  bool horizontal, const QSize &lc, const QSize &rc, const QSize &s, const QSize &t)
838 {
839  return horizontal
840  ? QSize(qMax(s.width(), t.width() + rc.width() + lc.width()),
841  s.height() + (qMax(rc.height(), qMax(lc.height(), t.height()))))
842  : QSize(s.width() + (qMax(rc.width(), qMax(lc.width(), t.width()))),
843  qMax(s.height(), t.height() + rc.height() + lc.height()));
844 }
845 
850 {
851  Q_D(const QTabWidget);
852  QSize lc(0, 0), rc(0, 0);
854  initStyleOption(&opt);
856 
857  if (d->leftCornerWidget)
858  lc = d->leftCornerWidget->sizeHint();
859  if(d->rightCornerWidget)
860  rc = d->rightCornerWidget->sizeHint();
861  if (!d->dirty) {
862  QTabWidget *that = (QTabWidget*)this;
863  that->setUpLayout(true);
864  }
865  QSize s(d->stack->sizeHint());
866  QSize t(d->tabs->sizeHint());
867  if(usesScrollButtons())
868  t = t.boundedTo(QSize(200,200));
869  else
871 
872  QSize sz = basicSize(d->pos == North || d->pos == South, lc, rc, s, t);
873 
874  return style()->sizeFromContents(QStyle::CT_TabWidget, &opt, sz, this)
876 }
877 
878 
888 {
889  Q_D(const QTabWidget);
890  QSize lc(0, 0), rc(0, 0);
891 
892  if(d->leftCornerWidget)
893  lc = d->leftCornerWidget->minimumSizeHint();
894  if(d->rightCornerWidget)
895  rc = d->rightCornerWidget->minimumSizeHint();
896  if (!d->dirty) {
897  QTabWidget *that = (QTabWidget*)this;
898  that->setUpLayout(true);
899  }
900  QSize s(d->stack->minimumSizeHint());
901  QSize t(d->tabs->minimumSizeHint());
902 
903  QSize sz = basicSize(d->pos == North || d->pos == South, lc, rc, s, t);
904 
906  initStyleOption(&opt);
907  opt.palette = palette();
909  return style()->sizeFromContents(QStyle::CT_TabWidget, &opt, sz, this)
911 }
912 
918 {
919  Q_D(const QTabWidget);
921  initStyleOption(&opt);
923 
924  QSize zero(0,0);
925  const QSize padding = style()->sizeFromContents(QStyle::CT_TabWidget, &opt, zero, this)
927 
928  QSize lc(0, 0), rc(0, 0);
929  if (d->leftCornerWidget)
930  lc = d->leftCornerWidget->sizeHint();
931  if(d->rightCornerWidget)
932  rc = d->rightCornerWidget->sizeHint();
933  if (!d->dirty) {
934  QTabWidget *that = (QTabWidget*)this;
935  that->setUpLayout(true);
936  }
937  QSize t(d->tabs->sizeHint());
938 
939  if(usesScrollButtons())
940  t = t.boundedTo(QSize(200,200));
941  else
943 
944  const bool tabIsHorizontal = (d->pos == North || d->pos == South);
945  const int contentsWidth = width - padding.width();
946  int stackWidth = contentsWidth;
947  if (!tabIsHorizontal)
948  stackWidth -= qMax(t.width(), qMax(lc.width(), rc.width()));
949 
950  int stackHeight = d->stack->heightForWidth(stackWidth);
951  QSize s(stackWidth, stackHeight);
952 
953  QSize contentSize = basicSize(tabIsHorizontal, lc, rc, s, t);
954  return (contentSize + padding).expandedTo(QApplication::globalStrut()).height();
955 }
956 
957 
962 {
963  setUpLayout();
964 }
965 
967 {
968  Q_Q(QTabWidget);
969  switch (pos) {
970  case QTabWidget::North:
971  tabs->setShape(shape == QTabWidget::Rounded ? QTabBar::RoundedNorth
973  break;
974  case QTabWidget::South:
975  tabs->setShape(shape == QTabWidget::Rounded ? QTabBar::RoundedSouth
977  break;
978  case QTabWidget::West:
979  tabs->setShape(shape == QTabWidget::Rounded ? QTabBar::RoundedWest
981  break;
982  case QTabWidget::East:
983  tabs->setShape(shape == QTabWidget::Rounded ? QTabBar::RoundedEast
985  break;
986  }
987  q->setUpLayout();
988 }
989 
1005 {
1006  Q_D(const QTabWidget);
1007  return d->pos;
1008 }
1009 
1011 {
1012  Q_D(QTabWidget);
1013  if (d->pos == pos)
1014  return;
1015  d->pos = pos;
1016  d->updateTabBarPosition();
1017 }
1018 
1030 bool QTabWidget::tabsClosable() const
1031 {
1032  return tabBar()->tabsClosable();
1033 }
1034 
1035 void QTabWidget::setTabsClosable(bool closeable)
1036 {
1037  if (tabsClosable() == closeable)
1038  return;
1039 
1040  tabBar()->setTabsClosable(closeable);
1041  if (closeable)
1043  this, SIGNAL(tabCloseRequested(int)));
1044  else
1046  this, SIGNAL(tabCloseRequested(int)));
1047  setUpLayout();
1048 }
1049 
1064 {
1065  return tabBar()->isMovable();
1066 }
1067 
1069 {
1070  tabBar()->setMovable(movable);
1071 }
1072 
1087 {
1088  Q_D(const QTabWidget);
1089  return d->shape;
1090 }
1091 
1093 {
1094  Q_D(QTabWidget);
1095  if (d->shape == s)
1096  return;
1097  d->shape = s;
1098  d->updateTabBarPosition();
1099 }
1100 
1105 {
1106  if (ev->type() == QEvent::LayoutRequest)
1107  setUpLayout();
1108  return QWidget::event(ev);
1109 }
1110 
1115 {
1116  if (ev->type() == QEvent::StyleChange
1117 #ifdef Q_WS_MAC
1118  || ev->type() == QEvent::MacSizeChange
1119 #endif
1120  )
1121  setUpLayout();
1123 }
1124 
1125 
1130 {
1131  Q_D(QTabWidget);
1132  if (((e->key() == Qt::Key_Tab || e->key() == Qt::Key_Backtab) &&
1133  count() > 1 && e->modifiers() & Qt::ControlModifier)
1134 #ifdef QT_KEYPAD_NAVIGATION
1135  || QApplication::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right) && count() > 1
1136 #endif
1137  ) {
1138  int pageCount = d->tabs->count();
1139  int page = currentIndex();
1140  int dx = (e->key() == Qt::Key_Backtab || e->modifiers() & Qt::ShiftModifier) ? -1 : 1;
1141 #ifdef QT_KEYPAD_NAVIGATION
1142  if (QApplication::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right))
1143  dx = e->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1;
1144 #endif
1145  for (int pass = 0; pass < pageCount; ++pass) {
1146  page+=dx;
1147  if (page < 0
1148 #ifdef QT_KEYPAD_NAVIGATION
1149  && !e->isAutoRepeat()
1150 #endif
1151  ) {
1152  page = count() - 1;
1153  } else if (page >= pageCount
1154 #ifdef QT_KEYPAD_NAVIGATION
1155  && !e->isAutoRepeat()
1156 #endif
1157  ) {
1158  page = 0;
1159  }
1160  if (d->tabs->isTabEnabled(page)) {
1161  setCurrentIndex(page);
1162  break;
1163  }
1164  }
1166  d->tabs->setFocus();
1167  } else {
1168  e->ignore();
1169  }
1170 }
1171 
1177 {
1178  Q_D(const QTabWidget);
1179  return d->stack->widget(index);
1180 }
1181 
1191 int QTabWidget::count() const
1192 {
1193  Q_D(const QTabWidget);
1194  return d->tabs->count();
1195 }
1196 
1197 #ifndef QT_NO_TOOLTIP
1198 
1204 {
1205  Q_D(QTabWidget);
1206  d->tabs->setTabToolTip(index, tip);
1207 }
1208 
1216 {
1217  Q_D(const QTabWidget);
1218  return d->tabs->tabToolTip(index);
1219 }
1220 #endif // QT_NO_TOOLTIP
1221 
1222 #ifndef QT_NO_WHATSTHIS
1223 
1233 {
1234  Q_D(QTabWidget);
1235  d->tabs->setTabWhatsThis(index, text);
1236 }
1237 
1248 {
1249  Q_D(const QTabWidget);
1250  return d->tabs->tabWhatsThis(index);
1251 }
1252 #endif // QT_NO_WHATSTHIS
1253 
1261 {
1262  Q_UNUSED(index)
1263 }
1264 
1272 {
1273  Q_UNUSED(index)
1274 }
1275 
1282 {
1283  Q_D(QTabWidget);
1284  if (documentMode()) {
1285  QStylePainter p(this, tabBar());
1289  opt.rect.moveLeft(w->x() + opt.rect.x());
1290  opt.rect.moveTop(w->y() + opt.rect.y());
1292  }
1296  opt.rect.moveLeft(w->x() + opt.rect.x());
1297  opt.rect.moveTop(w->y() + opt.rect.y());
1299  }
1300  return;
1301  }
1302  QStylePainter p(this);
1303 
1305  initStyleOption(&opt);
1306  opt.rect = d->panelRect;
1308 }
1309 
1325 {
1326  return d_func()->tabs->iconSize();
1327 }
1328 
1330 {
1331  d_func()->tabs->setIconSize(size);
1332 }
1333 
1350 {
1351  return d_func()->tabs->elideMode();
1352 }
1353 
1355 {
1356  d_func()->tabs->setElideMode(mode);
1357 }
1358 
1375 bool QTabWidget::usesScrollButtons() const
1376 {
1377  return d_func()->tabs->usesScrollButtons();
1378 }
1379 
1381 {
1382  d_func()->tabs->setUsesScrollButtons(useButtons);
1383 }
1384 
1400 bool QTabWidget::documentMode() const
1401 {
1402  Q_D(const QTabWidget);
1403  return d->tabs->documentMode();
1404 }
1405 
1407 {
1408  Q_D(QTabWidget);
1409  d->tabs->setDocumentMode(enabled);
1410  d->tabs->setExpanding(!enabled);
1411  d->tabs->setDrawBase(enabled);
1412  setUpLayout();
1413 }
1414 
1420 {
1421  // ### optimize by introduce QStackedLayout::clear()
1422  while (count())
1423  removeTab(0);
1424 }
1425 
1589 
1590 #include "moc_qtabwidget.cpp"
1591 
1592 #endif //QT_NO_TABWIDGET
void setDrawBase(bool drawTheBase)
Definition: qtabbar.cpp:800
QPoint pos() const
int currentIndex() const
double d
Definition: qnumeric_p.h:62
bool enabled
whether the widget is enabled
Definition: qwidget.h:157
void setTabsClosable(bool closeable)
QWidget * parentWidget() const
Returns the parent of this widget, or 0 if it does not have any parent widget.
Definition: qwidget.h:1035
bool blockSignals(bool b)
If block is true, signals emitted by this object are blocked (i.e., emitting a signal will not invoke...
Definition: qobject.cpp:1406
The QKeyEvent class describes a key event.
Definition: qevent.h:224
void setTabIcon(int index, const QIcon &icon)
Sets the icon for the tab at position index.
Definition: qtabwidget.cpp:529
QSize leftCornerWidgetSize
the size of the left-corner widget
Definition: qstyleoption.h:186
#define QT_END_NAMESPACE
This macro expands to.
Definition: qglobal.h:90
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
Definition: qwidget.cpp:10479
QSize size() const
static QString fromAscii(const char *, int size=-1)
Returns a QString initialized with the first size characters from the string str. ...
Definition: qstring.cpp:4276
void removeTab(int index)
Removes the tab at position index from this stack of widgets.
Definition: qtabwidget.cpp:637
int heightForWidth(int width) const
Reimplemented Function
Definition: qtabwidget.cpp:917
void moveLeft(int pos)
Moves the rectangle horizontally, leaving the rectangle&#39;s left edge at the given x coordinate...
Definition: qrect.h:350
void setCurrentWidget(QWidget *widget)
Makes widget the current widget.
Definition: qtabwidget.cpp:664
QStyle::State state
the style flags that are used when drawing the control
Definition: qstyleoption.h:88
QRect contentsRect() const
Returns the area inside the widget&#39;s margins.
Definition: qwidget.cpp:7544
void _q_showTab(int)
Ensures that the selected tab&#39;s page is visible and appropriately sized.
Definition: qtabwidget.cpp:764
bool usesScrollButtons() const
bool isVisible() const
Definition: qwidget.h:1005
static QSize globalStrut()
TabPosition
This enum type defines where QTabWidget draws the tab row:
Definition: qtabwidget.h:112
void setTabText(int index, const QString &)
Defines a new label for the page at position index&#39;s tab.
Definition: qtabwidget.cpp:504
void setCornerWidget(QWidget *w, Qt::Corner corner=Qt::TopRightCorner)
Sets the given widget to be shown in the specified corner of the tab widget.
Definition: qtabwidget.cpp:602
#define SLOT(a)
Definition: qobjectdefs.h:226
TextElideMode
Definition: qnamespace.h:263
bool hasHeightForWidth() const
Definition: qtabwidget.cpp:268
The QWidget class is the base class of all user interface objects.
Definition: qwidget.h:150
void setElideMode(Qt::TextElideMode)
QSize tabBarSize
the size of the tab bar
Definition: qstyleoption.h:184
QString tabText(int index) const
Returns the label text for the tab on the page at position index.
Definition: qtabwidget.cpp:515
QSize expandedTo(const QSize &) const
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition: qsize.h:187
void setTabPosition(TabPosition)
QSize iconSize() const
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
QLatin1String(DBUS_INTERFACE_DBUS))) Q_GLOBAL_STATIC_WITH_ARGS(QString
void _q_tabMoved(int from, int to)
Definition: qtabwidget.cpp:784
QSizePolicy size_policy
Definition: qwidget_p.h:756
int count() const
The QTabBar class provides a tab bar, e.g.
Definition: qtabbar.h:59
void setTabShape(TabShape s)
void currentChanged(int index)
This signal is emitted whenever the current page index changes.
The QString class provides a Unicode character string.
Definition: qstring.h:83
void setLineWidth(int)
Definition: qframe.cpp:368
bool event(QEvent *)
Reimplemented Function
virtual bool hasHeightForWidth() const
Definition: qwidget.cpp:10260
#define Q_ASSERT(cond)
Definition: qglobal.h:1823
#define Q_D(Class)
Definition: qglobal.h:2482
void setUsesScrollButtons(bool useButtons)
QSize boundedTo(const QSize &) const
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition: qsize.h:192
TabShape tabShape() const
QWidget * rightCornerWidget
Definition: qtabwidget.cpp:226
QWidget * cornerWidget(Qt::Corner corner=Qt::TopRightCorner) const
Returns the widget shown in the corner of the tab widget or 0.
Definition: qtabwidget.cpp:623
Q_DECL_CONSTEXPR const T & qMax(const T &a, const T &b)
Definition: qglobal.h:1217
bool tabsClosable
Whether or not a tab bar should place close buttons on each tab.
Definition: qtabbar.h:71
QStyle * style() const
Definition: qwidget.cpp:2742
void setObjectName(const QString &name)
Definition: qobject.cpp:1112
#define Q_Q(Class)
Definition: qglobal.h:2483
void update()
Updates the widget unless updates are disabled or the widget is hidden.
Definition: qwidget.cpp:10883
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition: qevent.cpp:999
int key() const
Returns the code of the key that was pressed or released.
Definition: qevent.h:231
QSize sizeHint() const
Reimplemented Function
Definition: qtabwidget.cpp:849
#define SIGNAL(a)
Definition: qobjectdefs.h:227
int width() const
Returns the width.
Definition: qsize.h:126
bool movable
This property holds whether the user can move the tabs within the tabbar area.
Definition: qtabwidget.h:73
#define QT_BEGIN_NAMESPACE
This macro expands to.
Definition: qglobal.h:89
QTabBar * tabBar() const
Returns the current QTabBar.
Definition: qtabwidget.cpp:753
bool hasHeightForWidth() const
Definition: qsizepolicy.h:136
void drawPrimitive(QStyle::PrimitiveElement pe, const QStyleOption &opt)
Use the widget&#39;s style to draw a primitive element pe specified by QStyleOption option.
Definition: qstylepainter.h:82
void setTabsClosable(bool closable)
Definition: qtabbar.cpp:2158
static bool connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
Creates a connection of the given type from the signal in the sender object to the method in the rece...
Definition: qobject.cpp:2580
QWidget(QWidget *parent=0, Qt::WindowFlags f=0)
Constructs a widget which is a child of parent, with widget flags set to f.
Definition: qwidget.cpp:1189
QWidget * currentWidget() const
Returns a pointer to the page currently being displayed by the tab dialog.
Definition: qtabwidget.cpp:652
void setExpanding(bool enabled)
Definition: qtabbar.cpp:2271
int width() const
void initFrom(const QWidget *w)
Definition: qstyleoption.h:99
bool isMovable() const
Definition: qtabbar.cpp:2293
const char * name
void resizeEvent(QResizeEvent *)
Reimplemented Function
Definition: qtabwidget.cpp:711
#define emit
Definition: qobjectdefs.h:76
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition: qwidget.cpp:9170
const QPalette & palette() const
The QResizeEvent class contains event parameters for resize events.
Definition: qevent.h:349
Qt::TextElideMode elideMode() const
void clear()
Removes all the pages, but does not delete them.
The QStyleOptionTabWidgetFrame class is used to describe the parameters for drawing the frame around ...
Definition: qstyleoption.h:175
void changeEvent(QEvent *)
Reimplemented Function
void show()
Shows the widget and its child widgets.
void initStyleOption(QStyleOptionTabWidgetFrame *option) const
Initialize option with the values from this QTabWidget.
Definition: qtabwidget.cpp:284
The QShowEvent class provides an event that is sent when a widget is shown.
Definition: qevent.h:380
void setTabBar(QTabBar *)
Replaces the dialog&#39;s QTabBar heading with the tab bar tb.
Definition: qtabwidget.cpp:724
QStackedWidget * stack
Definition: qtabwidget.cpp:219
int lineWidth
the line width for drawing the panel
Definition: qstyleoption.h:181
QSize minimumSizeHint() const
Returns a suitable minimum size for the tab widget.
Definition: qtabwidget.cpp:887
void keyPressEvent(QKeyEvent *)
Reimplemented Function
void setEnabled(bool)
Definition: qwidget.cpp:3447
void setMovable(bool movable)
Definition: qtabbar.cpp:2299
void moveTopLeft(const QPoint &p)
Moves the rectangle, leaving the top-left corner at the given position.
Definition: qrect.h:368
void setTabWhatsThis(int index, const QString &text)
Sets the What&#39;s This help text for the page at position index to text.
Corner
Definition: qnamespace.h:1456
static QDesktopWidget * desktop()
Returns the desktop widget (also called the root window).
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=0) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
The QStyleOptionTabBarBaseV2 class is used to describe the base of a tab bar, i.e.
Definition: qstyleoption.h:235
TabPosition tabPosition() const
QPalette palette
the palette that should be used when painting the control
Definition: qstyleoption.h:92
static bool disconnect(const QObject *sender, const char *signal, const QObject *receiver, const char *member)
Disconnects signal in object sender from method in object receiver.
Definition: qobject.cpp:2895
QTabWidget::TabShape shape
Definition: qtabwidget.cpp:223
void setFocusProxy(QWidget *)
Sets the widget&#39;s focus proxy to widget w.
Definition: qwidget.cpp:6537
#define Q_DECLARE_PUBLIC(Class)
Definition: qglobal.h:2477
QString tabToolTip(int index) const
Returns the tab tool tip for the page at position index or an empty string if no tool tip has been se...
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=0) const =0
Returns the sub-area for the given element as described in the provided style option.
QTabWidget(QWidget *parent=0)
Constructs a tabbed widget with parent parent.
Definition: qtabwidget.cpp:359
int addTab(QWidget *widget, const QString &)
Adds a tab with the given page and label to the tab widget, and returns the index of the tab in the t...
Definition: qtabwidget.cpp:407
void setTabToolTip(int index, const QString &tip)
Sets the tab tool tip for the page at position index to tip.
int y() const
Returns the y-coordinate of the rectangle&#39;s top edge.
Definition: qrect.h:255
QSize rightCornerWidgetSize
the size of the right-corner widget
Definition: qstyleoption.h:185
static void initStyleBaseOption(QStyleOptionTabBarBaseV2 *optTabBase, QTabBar *tabbar, QSize size)
Definition: qtabbar_p.h:208
void _q_removeTab(int)
Definition: qtabwidget.cpp:776
int x() const
Returns the x-coordinate of the rectangle&#39;s left edge.
Definition: qrect.h:252
QObject * parent() const
Returns a pointer to the parent object.
Definition: qobject.h:273
bool tabsClosable() const
int height() const
Returns the height.
Definition: qsize.h:129
static const int zero
The QRect class defines a rectangle in the plane using integer precision.
Definition: qrect.h:58
bool isAutoRepeat() const
Returns true if this event comes from an auto-repeating key; returns false if it comes from an initia...
Definition: qevent.h:237
QString tabWhatsThis(int index) const
Returns the What&#39;s This help text for the page at position index, or an empty string if no help text ...
void setTabEnabled(int index, bool)
If enable is true, the page at position index is enabled; otherwise the page at position index is dis...
Definition: qtabwidget.cpp:572
quint16 index
void setDocumentMode(bool set)
QObject * parent
Definition: qobject.h:92
QWidget * widget(int index) const
Returns the tab page at index position index or 0 if the index is out of range.
void tabCloseRequested(int index)
This signal is emitted when the close button on a tab is clicked.
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget...
Definition: qstylepainter.h:55
~QTabWidget()
Destroys the tabbed widget.
Definition: qtabwidget.cpp:383
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition: qcoreevent.h:310
void setCurrentIndex(int index)
Definition: qtabwidget.cpp:690
void paintEvent(QPaintEvent *)
Paints the tab widget&#39;s tab bar in response to the paint event.
The QSize class defines the size of a two-dimensional object using integer point precision.
Definition: qsize.h:53
bool isRightToLeft() const
Definition: qwidget.h:428
void setUpLayout(bool=false)
Definition: qtabwidget.cpp:798
The QTabWidget class provides a stack of tabbed widgets.
Definition: qtabwidget.h:60
QIcon tabIcon(int index) const
Returns the icon for the tab on the page at position index.
Definition: qtabwidget.cpp:540
int indexOf(QWidget *widget) const
Returns the index position of the page occupied by the widget w, or -1 if the widget cannot be found...
Definition: qtabwidget.cpp:701
Q_GUI_EXPORT QWidgetPrivate * qt_widget_private(QWidget *widget)
Definition: qwidget.cpp:12920
bool isTabEnabled(int index) const
Returns true if the page at position index is enabled; otherwise returns false.
Definition: qtabwidget.cpp:552
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
Definition: qwidget.cpp:10372
bool event(QEvent *)
This is the main event handler; it handles event event.
Definition: qwidget.cpp:8636
void moveTop(int pos)
Moves the rectangle vertically, leaving the rectangle&#39;s top edge at the given y coordinate.
Definition: qrect.h:353
void setIconSize(const QSize &size)
void updateTabBarPosition()
Definition: qtabwidget.cpp:966
bool isMovable() const
QTabWidget::TabPosition pos
Definition: qtabwidget.cpp:222
virtual void tabInserted(int index)
This virtual handler is called after a new tab was added or inserted at position index.
The QPaintEvent class contains event parameters for paint events.
Definition: qevent.h:298
QWidget * leftCornerWidget
Definition: qtabwidget.cpp:225
virtual void tabRemoved(int index)
This virtual handler is called after a tab was removed from position index.
void setSizePolicy(QSizePolicy)
Definition: qwidget.cpp:10198
The QStackedWidget class provides a stack of widgets where only one widget is visible at a time...
The QEvent class is the base class of all event classes.
Definition: qcoreevent.h:56
Type type() const
Returns the event type.
Definition: qcoreevent.h:303
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or 0 if no widget in this applicati...
bool documentMode() const
#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
The QStyleOptionTabWidgetFrameV2 class is used to describe the parameters for drawing the frame aroun...
Definition: qstyleoption.h:196
QRect rect
the area that should be used for various calculations and painting
Definition: qstyleoption.h:90
TabShape
This enum type defines the shape of the tabs:
Definition: qtabwidget.h:126
QTabBar::Shape shape
the tab shape used to draw the tabs
Definition: qstyleoption.h:183
#define text
Definition: qobjectdefs.h:80
static QSize basicSize(bool horizontal, const QSize &lc, const QSize &rc, const QSize &s, const QSize &t)
Definition: qtabwidget.cpp:836
QPoint topLeft() const
Returns the position of the rectangle&#39;s top-left corner.
Definition: qrect.h:288
void setMovable(bool movable)
int insertTab(int index, QWidget *widget, const QString &)
Inserts a tab with the given label and page into the tab widget at the specified index, and returns the index of the inserted tab in the tab bar.
Definition: qtabwidget.cpp:461
void showEvent(QShowEvent *)
Reimplemented Function
Definition: qtabwidget.cpp:961
The QIcon class provides scalable icons in different modes and states.
Definition: qicon.h:60