Qt
Internal/Contributor docs for the Qt SDK. <b>Note:</b> These are NOT official API docs; those are found <a href='https://doc.qt.io/'>here</a>.
Loading...
Searching...
No Matches
qtabwidget.cpp
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
3
4#include "qtabwidget.h"
5
6#include "private/qapplication_p.h"
7#include "private/qwidget_p.h"
8#include "private/qtabbar_p.h"
9#include "qapplication.h"
10#include "qbitmap.h"
11#include "qevent.h"
12#include "qlayout.h"
13#include "qstackedwidget.h"
14#include "qstyle.h"
15#include "qstyleoption.h"
16#include "qstylepainter.h"
17#include "qtabbar.h"
18#include "qtoolbutton.h"
19
21
22using namespace Qt::StringLiterals;
23
152{
153 Q_DECLARE_PUBLIC(QTabWidget)
154
155public:
159 void showTab(int);
160 void removeTab(int);
161 void tabMoved(int from, int to);
162 void init();
163 bool isAutoHidden() const
164 {
165 // see QTabBarPrivate::autoHideTabs()
166 return (tabs->autoHide() && tabs->count() <= 1);
167 }
168
169 void initBasicStyleOption(QStyleOptionTabWidgetFrame *option) const;
170
174 bool dirty;
179};
180
182 : tabs(nullptr), stack(nullptr), dirty(true),
183 pos(QTabWidget::North), shape(QTabWidget::Rounded),
184 leftCornerWidget(nullptr), rightCornerWidget(nullptr)
185{}
186
189
191{
192 Q_Q(QTabWidget);
193
194 stack = new QStackedWidget(q);
195 stack->setObjectName("qt_tabwidget_stackedwidget"_L1);
197 // hack so that QMacStyle::layoutSpacing() can detect tab widget pages
199
201 QTabBar *tabBar = new QTabBar(q);
202 tabBar->setObjectName("qt_tabwidget_tabbar"_L1);
203 tabBar->setDrawBase(false);
204 q->setTabBar(tabBar);
205
208#ifdef QT_KEYPAD_NAVIGATION
209 if (QApplicationPrivate::keypadNavigationEnabled())
210 q->setFocusPolicy(Qt::NoFocus);
211 else
212#endif
213 q->setFocusPolicy(Qt::TabFocus);
214 q->setFocusProxy(tabs);
215 q->setTabPosition(static_cast<QTabWidget::TabPosition> (q->style()->styleHint(
217
218}
219
225{
226 Q_D(const QTabWidget);
227 bool has = d->size_policy.hasHeightForWidth();
228 if (!has && d->stack)
229 has = d->stack->hasHeightForWidth();
230 return has;
231}
232
239void QTabWidgetPrivate::initBasicStyleOption(QStyleOptionTabWidgetFrame *option) const
240{
241 Q_Q(const QTabWidget);
242 option->initFrom(q);
243
244 if (q->documentMode())
245 option->lineWidth = 0;
246 else
247 option->lineWidth = q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, q);
248
249 switch (pos) {
253 break;
257 break;
258 case QTabWidget::West:
261 break;
262 case QTabWidget::East:
265 break;
266 }
267
268 option->tabBarRect = q->tabBar()->geometry();
269}
270
278void QTabWidget::initStyleOption(QStyleOptionTabWidgetFrame *option) const
279{
280 if (!option)
281 return;
282
283 Q_D(const QTabWidget);
284 d->initBasicStyleOption(option);
285
286 int exth = style()->pixelMetric(QStyle::PM_TabBarBaseHeight, nullptr, this);
287 QSize t(0, d->stack->frameWidth());
288 if (d->tabs->isVisibleTo(const_cast<QTabWidget *>(this))) {
289 t = d->tabs->sizeHint();
290 if (documentMode()) {
291 if (tabPosition() == East || tabPosition() == West) {
292 t.setHeight(height());
293 } else {
294 t.setWidth(width());
295 }
296 }
297 }
298
299 if (d->rightCornerWidget) {
300 const QSize rightCornerSizeHint = d->rightCornerWidget->sizeHint();
301 const QSize bounds(rightCornerSizeHint.width(), t.height() - exth);
302 option->rightCornerWidgetSize = rightCornerSizeHint.boundedTo(bounds);
303 } else {
304 option->rightCornerWidgetSize = QSize(0, 0);
305 }
306
307 if (d->leftCornerWidget) {
308 const QSize leftCornerSizeHint = d->leftCornerWidget->sizeHint();
309 const QSize bounds(leftCornerSizeHint.width(), t.height() - exth);
310 option->leftCornerWidgetSize = leftCornerSizeHint.boundedTo(bounds);
311 } else {
312 option->leftCornerWidgetSize = QSize(0, 0);
313 }
314
315 option->tabBarSize = t;
316
317 QRect selectedTabRect = tabBar()->tabRect(tabBar()->currentIndex());
318 selectedTabRect.moveTopLeft(selectedTabRect.topLeft() + option->tabBarRect.topLeft());
319 option->selectedTabRect = selectedTabRect;
320}
321
326 : QWidget(*new QTabWidgetPrivate, parent, { })
327{
328 Q_D(QTabWidget);
329 d->init();
330}
331
332
339
362{
363 return insertTab(-1, child, label);
364}
365
366
379{
380 return insertTab(-1, child, icon, label);
381}
382
383
418{
419 return insertTab(index, w, QIcon(), label);
420}
421
422
436{
437 Q_D(QTabWidget);
438 if (!w)
439 return -1;
440 index = d->stack->insertWidget(index, w);
441 d->tabs->insertTab(index, icon, label);
442 setUpLayout();
444
445 return index;
446}
447
448
462{
463 Q_D(QTabWidget);
464 d->tabs->setTabText(index, label);
465 setUpLayout();
466}
467
473{
474 Q_D(const QTabWidget);
475 return d->tabs->tabText(index);
476}
477
482{
483 Q_D(QTabWidget);
484 d->tabs->setTabIcon(index, icon);
485 setUpLayout();
486}
487
493{
494 Q_D(const QTabWidget);
495 return d->tabs->tabIcon(index);
496}
497
505{
506 Q_D(const QTabWidget);
507 return d->tabs->isTabEnabled(index);
508}
509
525{
526 Q_D(QTabWidget);
527 d->tabs->setTabEnabled(index, enable);
528 if (QWidget *widget = d->stack->widget(index))
530}
531
540{
541 Q_D(const QTabWidget);
542 return d->tabs->isTabVisible(index);
543}
544
553void QTabWidget::setTabVisible(int index, bool visible)
554{
555 Q_D(QTabWidget);
556 QWidget *widget = d->stack->widget(index);
557 bool currentVisible = d->tabs->isTabVisible(d->tabs->currentIndex());
558 d->tabs->setTabVisible(index, visible);
559 if (!visible) {
560 if (widget)
561 widget->setVisible(false);
562 } else if (!currentVisible) {
564 if (widget)
565 widget->setVisible(true);
566 }
567 setUpLayout();
568}
569
593{
594 Q_D(QTabWidget);
595 if (widget && widget->parentWidget() != this)
596 widget->setParent(this);
597
598 if (corner & Qt::TopRightCorner) {
599 if (d->rightCornerWidget)
600 d->rightCornerWidget->hide();
601 d->rightCornerWidget = widget;
602 } else {
603 if (d->leftCornerWidget)
604 d->leftCornerWidget->hide();
605 d->leftCornerWidget = widget;
606 }
607 setUpLayout();
608}
609
614{
615 Q_D(const QTabWidget);
616 if (corner & Qt::TopRightCorner)
617 return d->rightCornerWidget;
618 return d->leftCornerWidget;
619}
620
628{
629 Q_D(QTabWidget);
630 if (QWidget *w = d->stack->widget(index))
631 d->stack->removeWidget(w);
632}
633
643{
644 Q_D(const QTabWidget);
645 return d->stack->currentWidget();
646}
647
655{
656 Q_D(const QTabWidget);
657 d->tabs->setCurrentIndex(indexOf(widget));
658}
659
660
672{
673 Q_D(const QTabWidget);
674 return d->tabs->currentIndex();
675}
676
678{
679 Q_D(QTabWidget);
680 d->tabs->setCurrentIndex(index);
681}
682
683
689{
690 Q_D(const QTabWidget);
691 return d->stack->indexOf(w);
692}
693
694
699{
701 setUpLayout();
702}
703
712{
713 Q_D(QTabWidget);
714 Q_ASSERT(tb);
715
716 if (tb->parentWidget() != this) {
717 tb->setParent(this);
718 tb->show();
719 }
720 delete d->tabs;
721 d->tabs = tb;
722 setFocusProxy(d->tabs);
731 if (d->tabs->tabsClosable())
734 tb->setExpanding(!documentMode());
735 setUpLayout();
736}
737
738
745{
746 Q_D(const QTabWidget);
747 return d->tabs;
748}
749
750/*
751 Ensures that the selected tab's page is visible and appropriately
752 sized.
753*/
754
756{
757 Q_Q(QTabWidget);
758 if (index < stack->count() && index >= 0)
760 emit q->currentChanged(index);
761}
762
764{
765 Q_Q(QTabWidget);
767 q->setUpLayout();
768 q->tabRemoved(index);
769}
770
771void QTabWidgetPrivate::tabMoved(int from, int to)
772{
773 const QSignalBlocker blocker(stack);
774 QWidget *w = stack->widget(from);
776 stack->insertWidget(to, w);
777}
778
779/*
780 Set up the layout.
781 Get subrect from the current style, and set the geometry for the
782 stack widget, tab bar and corner widgets.
783*/
784void QTabWidget::setUpLayout(bool onlyCheck)
785{
786 Q_D(QTabWidget);
787 if (onlyCheck && !d->dirty)
788 return; // nothing to do
789
790 if (!isVisible()) {
791 // this must be done immediately, because QWidgetItem relies on it (even if !isVisible())
792 QStyleOptionTabWidgetFrame basicOption;
793 d->initBasicStyleOption(&basicOption);
794 d->setLayoutItemMargins(QStyle::SE_TabWidgetLayoutItem, &basicOption);
795 d->dirty = true;
796 return; // we'll do it later
797 }
798
799 QStyleOptionTabWidgetFrame option;
801 d->setLayoutItemMargins(QStyle::SE_TabWidgetLayoutItem, &option);
802
808
809 d->tabs->setGeometry(tabRect);
810 d->stack->setGeometry(contentsRect);
811 if (d->leftCornerWidget)
812 d->leftCornerWidget->setGeometry(leftCornerRect);
813 if (d->rightCornerWidget)
814 d->rightCornerWidget->setGeometry(rightCornerRect);
815
816 if (!onlyCheck)
817 update();
819}
820
824static inline QSize basicSize(
825 bool horizontal, const QSize &lc, const QSize &rc, const QSize &s, const QSize &t)
826{
827 return horizontal
828 ? QSize(qMax(s.width(), t.width() + rc.width() + lc.width()),
829 s.height() + (qMax(rc.height(), qMax(lc.height(), t.height()))))
830 : QSize(s.width() + (qMax(rc.width(), qMax(lc.width(), t.width()))),
831 qMax(s.height(), t.height() + rc.height() + lc.height()));
832}
833
838{
839 Q_D(const QTabWidget);
840 QSize lc(0, 0), rc(0, 0);
841 QStyleOptionTabWidgetFrame opt;
844
845 if (d->leftCornerWidget)
846 lc = d->leftCornerWidget->sizeHint();
847 if (d->rightCornerWidget)
848 rc = d->rightCornerWidget->sizeHint();
849 if (!d->dirty) {
850 QTabWidget *that = const_cast<QTabWidget*>(this);
851 that->setUpLayout(true);
852 }
853 QSize s;
854 for (int i=0; i< d->stack->count(); ++i) {
855 if (const QWidget* w = d->stack->widget(i)) {
856 if (d->tabs->isTabVisible(i))
857 s = s.expandedTo(w->sizeHint());
858 }
859 }
860 QSize t;
861 if (!d->isAutoHidden()) {
862 t = d->tabs->sizeHint();
863 if (usesScrollButtons())
864 t = t.boundedTo(QSize(200,200));
865 else
867 }
868
869 QSize sz = basicSize(d->pos == North || d->pos == South, lc, rc, s, t);
870
871 return style()->sizeFromContents(QStyle::CT_TabWidget, &opt, sz, this);
872}
873
874
881{
882 Q_D(const QTabWidget);
883 QSize lc(0, 0), rc(0, 0);
884
885 if (d->leftCornerWidget)
886 lc = d->leftCornerWidget->minimumSizeHint();
887 if (d->rightCornerWidget)
888 rc = d->rightCornerWidget->minimumSizeHint();
889 if (!d->dirty) {
890 QTabWidget *that = const_cast<QTabWidget*>(this);
891 that->setUpLayout(true);
892 }
893 QSize s(d->stack->minimumSizeHint());
894 QSize t;
895 if (!d->isAutoHidden())
896 t = d->tabs->minimumSizeHint();
897
898 QSize sz = basicSize(d->pos == North || d->pos == South, lc, rc, s, t);
899
900 QStyleOptionTabWidgetFrame opt;
902 opt.palette = palette();
904 return style()->sizeFromContents(QStyle::CT_TabWidget, &opt, sz, this);
905}
906
911{
912 Q_D(const QTabWidget);
913 QStyleOptionTabWidgetFrame opt;
916
917 QSize zero(0,0);
918 const QSize padding = style()->sizeFromContents(QStyle::CT_TabWidget, &opt, zero, this);
919
920 QSize lc(0, 0), rc(0, 0);
921 if (d->leftCornerWidget)
922 lc = d->leftCornerWidget->sizeHint();
923 if (d->rightCornerWidget)
924 rc = d->rightCornerWidget->sizeHint();
925 if (!d->dirty) {
926 QTabWidget *that = const_cast<QTabWidget*>(this);
927 that->setUpLayout(true);
928 }
929 QSize t;
930 if (!d->isAutoHidden()) {
931 t = d->tabs->sizeHint();
932 if (usesScrollButtons())
933 t = t.boundedTo(QSize(200,200));
934 else
936 }
937
938 const bool tabIsHorizontal = (d->pos == North || d->pos == South);
939 const int contentsWidth = width - padding.width();
940 int stackWidth = contentsWidth;
941 if (!tabIsHorizontal)
942 stackWidth -= qMax(t.width(), qMax(lc.width(), rc.width()));
943
944 int stackHeight = d->stack->heightForWidth(stackWidth);
945 QSize s(stackWidth, stackHeight);
946
947 QSize contentSize = basicSize(tabIsHorizontal, lc, rc, s, t);
948 return (contentSize + padding).height();
949}
950
951
956{
957 setUpLayout();
958}
959
983
996{
997 Q_D(const QTabWidget);
998 return d->pos;
999}
1000
1002{
1003 Q_D(QTabWidget);
1004 if (d->pos == pos)
1005 return;
1006 d->pos = pos;
1007 d->updateTabBarPosition();
1008}
1009
1019{
1020 return tabBar()->tabsClosable();
1021}
1022
1024{
1025 if (tabsClosable() == closeable)
1026 return;
1027
1028 tabBar()->setTabsClosable(closeable);
1029 if (closeable)
1031 this, SIGNAL(tabCloseRequested(int)));
1032 else
1034 this, SIGNAL(tabCloseRequested(int)));
1035 setUpLayout();
1036}
1037
1049{
1050 return tabBar()->isMovable();
1051}
1052
1053void QTabWidget::setMovable(bool movable)
1054{
1056}
1057
1069{
1070 Q_D(const QTabWidget);
1071 return d->shape;
1072}
1073
1075{
1076 Q_D(QTabWidget);
1077 if (d->shape == s)
1078 return;
1079 d->shape = s;
1080 d->updateTabBarPosition();
1081}
1082
1087{
1088 if (ev->type() == QEvent::LayoutRequest)
1089 setUpLayout();
1090 return QWidget::event(ev);
1091}
1092
1097{
1098 if (ev->type() == QEvent::StyleChange
1099#ifdef Q_OS_MAC
1100 || ev->type() == QEvent::MacSizeChange
1101#endif
1102 )
1103 setUpLayout();
1105}
1106
1107
1112{
1113 Q_D(QTabWidget);
1114 if (((e->key() == Qt::Key_Tab || e->key() == Qt::Key_Backtab) &&
1115 count() > 1 && e->modifiers() & Qt::ControlModifier)
1116#ifdef QT_KEYPAD_NAVIGATION
1117 || QApplicationPrivate::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right) && count() > 1
1118#endif
1119 ) {
1120 int pageCount = d->tabs->count();
1121 int page = currentIndex();
1122 int dx = (e->key() == Qt::Key_Backtab || e->modifiers() & Qt::ShiftModifier) ? -1 : 1;
1123#ifdef QT_KEYPAD_NAVIGATION
1124 if (QApplicationPrivate::keypadNavigationEnabled() && (e->key() == Qt::Key_Left || e->key() == Qt::Key_Right))
1125 dx = e->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1;
1126#endif
1127 for (int pass = 0; pass < pageCount; ++pass) {
1128 page+=dx;
1129 if (page < 0
1130#ifdef QT_KEYPAD_NAVIGATION
1131 && !e->isAutoRepeat()
1132#endif
1133 ) {
1134 page = count() - 1;
1135 } else if (page >= pageCount
1136#ifdef QT_KEYPAD_NAVIGATION
1137 && !e->isAutoRepeat()
1138#endif
1139 ) {
1140 page = 0;
1141 }
1142 if (d->tabs->isTabEnabled(page) && d->tabs->isTabVisible(page)) {
1144 break;
1145 }
1146 }
1148 d->tabs->setFocus();
1149 } else {
1150 e->ignore();
1151 }
1152}
1153
1159{
1160 Q_D(const QTabWidget);
1161 return d->stack->widget(index);
1162}
1163
1171{
1172 Q_D(const QTabWidget);
1173 return d->tabs->count();
1174}
1175
1176#if QT_CONFIG(tooltip)
1182void QTabWidget::setTabToolTip(int index, const QString & tip)
1183{
1184 Q_D(QTabWidget);
1185 d->tabs->setTabToolTip(index, tip);
1186}
1187
1194QString QTabWidget::tabToolTip(int index) const
1195{
1196 Q_D(const QTabWidget);
1197 return d->tabs->tabToolTip(index);
1198}
1199#endif // QT_CONFIG(tooltip)
1200
1201#if QT_CONFIG(whatsthis)
1208void QTabWidget::setTabWhatsThis(int index, const QString &text)
1209{
1210 Q_D(QTabWidget);
1211 d->tabs->setTabWhatsThis(index, text);
1212}
1213
1220QString QTabWidget::tabWhatsThis(int index) const
1221{
1222 Q_D(const QTabWidget);
1223 return d->tabs->tabWhatsThis(index);
1224}
1225#endif // QT_CONFIG(whatsthis)
1226
1234{
1235 Q_UNUSED(index);
1236}
1237
1245{
1246 Q_UNUSED(index);
1247}
1248
1255{
1256 Q_D(QTabWidget);
1257 if (documentMode()) {
1258 QStylePainter p(this, tabBar());
1260 QStyleOptionTabBarBase opt;
1262 opt.rect.moveLeft(w->x() + opt.rect.x());
1263 opt.rect.moveTop(w->y() + opt.rect.y());
1264 p.drawPrimitive(QStyle::PE_FrameTabBarBase, opt);
1265 }
1267 QStyleOptionTabBarBase opt;
1269 opt.rect.moveLeft(w->x() + opt.rect.x());
1270 opt.rect.moveTop(w->y() + opt.rect.y());
1271 p.drawPrimitive(QStyle::PE_FrameTabBarBase, opt);
1272 }
1273 return;
1274 }
1275 QStylePainter p(this);
1276
1277 QStyleOptionTabWidgetFrame opt;
1279 opt.rect = d->panelRect;
1280 p.drawPrimitive(QStyle::PE_FrameTabWidget, opt);
1281}
1282
1295{
1296 return d_func()->tabs->iconSize();
1297}
1298
1300{
1301 d_func()->tabs->setIconSize(size);
1302}
1303
1317{
1318 return d_func()->tabs->elideMode();
1319}
1320
1322{
1323 d_func()->tabs->setElideMode(mode);
1324}
1325
1340{
1341 return d_func()->tabs->usesScrollButtons();
1342}
1343
1345{
1346 d_func()->tabs->setUsesScrollButtons(useButtons);
1347}
1348
1362{
1363 Q_D(const QTabWidget);
1364 return d->tabs->documentMode();
1365}
1366
1368{
1369 Q_D(QTabWidget);
1370 d->tabs->setDocumentMode(enabled);
1371 d->tabs->setExpanding(!enabled);
1372 d->tabs->setDrawBase(enabled);
1373 setUpLayout();
1374}
1375
1388{
1389 Q_D(const QTabWidget);
1390 return d->tabs->autoHide();
1391}
1392
1394{
1395 Q_D(QTabWidget);
1396 return d->tabs->setAutoHide(enabled);
1397}
1398
1404{
1405 // ### optimize by introduce QStackedLayout::clear()
1406 while (count())
1407 removeTab(0);
1408}
1409
1423
1425
1426#include "moc_qtabwidget.cpp"
static QWidget * focusWidget()
Returns the application widget that has the keyboard input focus, or \nullptr if no widget in this ap...
\inmodule QtCore
Definition qcoreevent.h:45
@ StyleChange
Definition qcoreevent.h:136
@ LayoutRequest
Definition qcoreevent.h:112
@ MacSizeChange
Definition qcoreevent.h:217
void ignore()
Clears the accept flag parameter of the event object, the equivalent of calling setAccepted(false).
Definition qcoreevent.h:311
void setLineWidth(int)
Definition qframe.cpp:336
QScreen * primaryScreen
the primary (or default) screen of the application.
The QIcon class provides scalable icons in different modes and states.
Definition qicon.h:20
The QKeyEvent class describes a key event.
Definition qevent.h:424
Qt::KeyboardModifiers modifiers() const
Returns the keyboard modifier flags that existed immediately after the event occurred.
Definition qevent.cpp:1468
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:444
int key() const
Returns the code of the key that was pressed or released.
Definition qevent.h:434
static QMetaObject::Connection connect(const typename QtPrivate::FunctionPointer< Func1 >::Object *sender, Func1 signal, const typename QtPrivate::FunctionPointer< Func2 >::Object *receiverPrivate, Func2 slot, Qt::ConnectionType type=Qt::AutoConnection)
Definition qobject_p.h:299
static QMetaObject::Connection connect(const QObject *sender, const char *signal, const QObject *receiver, const char *member, Qt::ConnectionType=Qt::AutoConnection)
\threadsafe
Definition qobject.cpp:2960
Q_WEAK_OVERLOAD void setObjectName(const QString &name)
Sets the object's name to name.
Definition qobject.h:127
The QPaintEvent class contains event parameters for paint events.
Definition qevent.h:486
\inmodule QtCore\reentrant
Definition qrect.h:30
constexpr void moveTopLeft(const QPoint &p) noexcept
Moves the rectangle, leaving the top-left corner at the given position.
Definition qrect.h:304
constexpr QPoint topLeft() const noexcept
Returns the position of the rectangle's top-left corner.
Definition qrect.h:221
constexpr void moveLeft(int pos) noexcept
Moves the rectangle horizontally, leaving the rectangle's left edge at the given x coordinate.
Definition qrect.h:286
constexpr int x() const noexcept
Returns the x-coordinate of the rectangle's left edge.
Definition qrect.h:185
constexpr QSize size() const noexcept
Returns the size of the rectangle.
Definition qrect.h:242
constexpr int y() const noexcept
Returns the y-coordinate of the rectangle's top edge.
Definition qrect.h:188
constexpr void moveTop(int pos) noexcept
Moves the rectangle vertically, leaving the rectangle's top edge at the given y coordinate.
Definition qrect.h:289
The QResizeEvent class contains event parameters for resize events.
Definition qevent.h:548
QRect virtualGeometry
the pixel geometry of the virtual desktop to which this screen belongs
Definition qscreen.h:47
QSize virtualSize
the pixel size of the virtual desktop to which this screen belongs
Definition qscreen.h:43
The QShowEvent class provides an event that is sent when a widget is shown.
Definition qevent.h:578
Exception-safe wrapper around QObject::blockSignals().
Definition qobject.h:483
The QSizePolicy class is a layout attribute describing horizontal and vertical resizing policy.
Definition qsizepolicy.h:18
\inmodule QtCore
Definition qsize.h:25
constexpr QSize boundedTo(const QSize &) const noexcept
Returns a size holding the minimum width and height of this size and the given otherSize.
Definition qsize.h:197
constexpr int height() const noexcept
Returns the height.
Definition qsize.h:133
constexpr int width() const noexcept
Returns the width.
Definition qsize.h:130
constexpr QSize expandedTo(const QSize &) const noexcept
Returns a size holding the maximum width and height of this size and the given otherSize.
Definition qsize.h:192
The QStackedWidget class provides a stack of widgets where only one widget is visible at a time.
void widgetRemoved(int index)
This signal is emitted whenever a widget is removed.
void setCurrentIndex(int index)
int insertWidget(int index, QWidget *w)
Inserts the given widget at the given index in the QStackedWidget.
void removeWidget(QWidget *w)
Removes widget from the QStackedWidget.
QWidget * widget(int) const
Returns the widget at the given index, or \nullptr if there is no such widget.
\macro QT_RESTRICTED_CAST_FROM_ASCII
Definition qstring.h:129
QStyle::State state
QPalette palette
The QStylePainter class is a convenience class for drawing QStyle elements inside a widget.
@ State_None
Definition qstyle.h:66
@ CT_TabWidget
Definition qstyle.h:564
virtual QSize sizeFromContents(ContentsType ct, const QStyleOption *opt, const QSize &contentsSize, const QWidget *w=nullptr) const =0
Returns the size of the element described by the specified option and type, based on the provided con...
@ SH_TabWidget_DefaultTabPosition
Definition qstyle.h:671
virtual QRect subElementRect(SubElement subElement, const QStyleOption *option, const QWidget *widget=nullptr) const =0
Returns the sub-area for the given element as described in the provided style option.
@ PM_DefaultFrameWidth
Definition qstyle.h:420
@ PM_TabBarBaseHeight
Definition qstyle.h:442
@ PE_FrameTabWidget
Definition qstyle.h:111
@ PE_FrameTabBarBase
Definition qstyle.h:115
virtual int pixelMetric(PixelMetric metric, const QStyleOption *option=nullptr, const QWidget *widget=nullptr) const =0
Returns the value of the given pixel metric.
@ SE_TabWidgetTabPane
Definition qstyle.h:270
@ SE_TabWidgetRightCorner
Definition qstyle.h:273
@ SE_TabWidgetLayoutItem
Definition qstyle.h:302
@ SE_TabWidgetTabBar
Definition qstyle.h:269
@ SE_TabWidgetLeftCorner
Definition qstyle.h:272
@ SE_TabWidgetTabContents
Definition qstyle.h:271
static void initStyleBaseOption(QStyleOptionTabBarBase *optTabBase, QTabBar *tabbar, QSize size)
Definition qtabbar_p.h:211
The QTabBar class provides a tab bar, e.g.
Definition qtabbar.h:19
void setTabsClosable(bool closable)
Definition qtabbar.cpp:2563
int count
the number of tabs in the tab bar
Definition qtabbar.h:24
void setShape(Shape shape)
Definition qtabbar.cpp:878
void currentChanged(int index)
This signal is emitted when the tab bar's current tab changes.
void removeTab(int index)
Removes the tab at position index.
Definition qtabbar.cpp:1009
bool isMovable() const
Definition qtabbar.cpp:2684
void tabBarDoubleClicked(int index)
This signal is emitted when the user double clicks on a tab at index.
void tabCloseRequested(int index)
void tabMoved(int from, int to)
void setDrawBase(bool drawTheBase)
Definition qtabbar.cpp:897
QRect tabRect(int index) const
Returns the visual rectangle of the tab at position index, or a null rectangle if index is hidden,...
Definition qtabbar.cpp:1342
bool autoHide
If true, the tab bar is automatically hidden when it contains less than 2 tabs.
Definition qtabbar.h:35
void setMovable(bool movable)
Definition qtabbar.cpp:2690
void tabBarClicked(int index)
This signal is emitted when user clicks on a tab at an index.
Shape
This enum type lists the built-in shapes supported by QTabBar.
Definition qtabbar.h:42
@ RoundedSouth
Definition qtabbar.h:42
@ RoundedNorth
Definition qtabbar.h:42
@ TriangularEast
Definition qtabbar.h:43
@ RoundedWest
Definition qtabbar.h:42
@ TriangularSouth
Definition qtabbar.h:43
@ RoundedEast
Definition qtabbar.h:42
@ TriangularWest
Definition qtabbar.h:43
@ TriangularNorth
Definition qtabbar.h:43
bool tabsClosable
Whether or not a tab bar should place close buttons on each tab.
Definition qtabbar.h:29
QTabWidget::TabPosition pos
void tabMoved(int from, int to)
QStackedWidget * stack
QWidget * rightCornerWidget
QTabWidget::TabShape shape
bool isAutoHidden() const
void updateTabBarPosition()
void initBasicStyleOption(QStyleOptionTabWidgetFrame *option) const
QWidget * leftCornerWidget
The QTabWidget class provides a stack of tabbed widgets.
Definition qtabwidget.h:20
QString tabText(int index) const
Returns the label text for the tab on the page at position index.
bool usesScrollButtons
Whether or not a tab bar should use buttons to scroll tabs when it has many tabs.
Definition qtabwidget.h:28
bool hasHeightForWidth() const override
\reimp
int indexOf(const QWidget *widget) const
Returns the index position of the page occupied by the widget w, or -1 if the widget cannot be found.
QSize iconSize
The size for icons in the tab bar.
Definition qtabwidget.h:26
void setTabEnabled(int index, bool enabled)
If enable is true, the page at position index is enabled; otherwise the page at position index is dis...
QTabWidget(QWidget *parent=nullptr)
Constructs a tabbed widget with parent parent.
TabPosition
This enum type defines where QTabWidget draws the tab row:
Definition qtabwidget.h:74
void setTabBarAutoHide(bool enabled)
bool event(QEvent *) override
\reimp
void setTabsClosable(bool closeable)
void setUsesScrollButtons(bool useButtons)
virtual void tabInserted(int index)
This virtual handler is called after a new tab was added or inserted at position index.
void changeEvent(QEvent *) override
\reimp
QIcon tabIcon(int index) const
Returns the icon for the tab on the page at position index.
void setCurrentIndex(int index)
void setElideMode(Qt::TextElideMode mode)
TabShape tabShape
the shape of the tabs in this tab widget
Definition qtabwidget.h:23
void keyPressEvent(QKeyEvent *) override
\reimp
void setTabBar(QTabBar *)
Replaces the dialog's QTabBar heading with the tab bar tb.
~QTabWidget()
Destroys the tabbed widget.
int currentIndex
the index position of the current tab page
Definition qtabwidget.h:24
void setCurrentWidget(QWidget *widget)
Makes widget the current widget.
bool tabBarAutoHide
If true, the tab bar is automatically hidden when it contains less than 2 tabs.
Definition qtabwidget.h:32
int heightForWidth(int width) const override
\reimp
QSize sizeHint() const override
\reimp
bool movable
This property holds whether the user can move the tabs within the tabbar area.
Definition qtabwidget.h:31
void tabBarDoubleClicked(int index)
This signal is emitted when the user double clicks on a tab at an index.
TabPosition tabPosition
the position of the tabs in this tab widget
Definition qtabwidget.h:22
void setDocumentMode(bool set)
bool tabsClosable
whether close buttons are automatically added to each tab.
Definition qtabwidget.h:30
void tabBarClicked(int index)
This signal is emitted when user clicks on a tab at an index.
void setTabShape(TabShape s)
virtual void initStyleOption(QStyleOptionTabWidgetFrame *option) const
Initialize option with the values from this QTabWidget.
bool isTabVisible(int index) const
Returns true if the page at position index is visible; otherwise returns false.
void resizeEvent(QResizeEvent *) override
\reimp
void tabCloseRequested(int index)
TabShape
This enum type defines the shape of the tabs: \value Rounded The tabs are drawn with a rounded look.
Definition qtabwidget.h:85
void paintEvent(QPaintEvent *) override
Paints the tab widget's tab bar in response to the paint event.
void clear()
Removes all the pages, but does not delete them.
void setTabText(int index, const QString &text)
Defines a new label for the page at position index's tab.
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,...
QWidget * currentWidget() const
Returns a pointer to the page currently being displayed by the tab dialog.
void setCornerWidget(QWidget *w, Qt::Corner corner=Qt::TopRightCorner)
Sets the given widget to be shown in the specified corner of the tab widget.
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...
QSize minimumSizeHint() const override
\reimp
virtual void tabRemoved(int index)
This virtual handler is called after a tab was removed from position index.
bool documentMode
Whether or not the tab widget is rendered in a mode suitable for document pages.
Definition qtabwidget.h:29
void setIconSize(const QSize &size)
Qt::TextElideMode elideMode
how to elide text in the tab bar
Definition qtabwidget.h:27
QWidget * widget(int index) const
Returns the tab page at index position index or \nullptr if the index is out of range.
void setTabPosition(TabPosition position)
void removeTab(int index)
Removes the tab at position index from this stack of widgets.
void setMovable(bool movable)
QWidget * cornerWidget(Qt::Corner corner=Qt::TopRightCorner) const
Returns the widget shown in the corner of the tab widget or \nullptr.
int count
the number of tabs in the tab bar
Definition qtabwidget.h:25
bool isTabEnabled(int index) const
Returns true if the page at position index is enabled; otherwise returns false.
QTabBar * tabBar() const
Returns the current QTabBar.
bool isMovable() const
void setTabIcon(int index, const QIcon &icon)
Sets the icon for the tab at position index.
void setTabVisible(int index, bool visible)
If visible is true, the page at position index is visible; otherwise the page at position index is hi...
void showEvent(QShowEvent *) override
\reimp
The QWidget class is the base class of all user interface objects.
Definition qwidget.h:99
void setParent(QWidget *parent)
Sets the parent of the widget to parent, and resets the window flags.
void updateGeometry()
Notifies the layout system that this widget has changed and may need to change geometry.
void setSizePolicy(QSizePolicy)
QSize size
the size of the widget excluding any window frame
Definition qwidget.h:113
void setEnabled(bool)
Definition qwidget.cpp:3358
void setFocusProxy(QWidget *)
Sets the widget's focus proxy to widget w.
Definition qwidget.cpp:6368
QPalette palette
the widget's palette
Definition qwidget.h:132
int width
the width of the widget excluding any window frame
Definition qwidget.h:114
QPoint pos
the position of the widget within its parent widget
Definition qwidget.h:111
QRect contentsRect() const
Returns the area inside the widget's margins.
Definition qwidget.cpp:7667
void hide()
Hides the widget.
Definition qwidget.cpp:8135
int height
the height of the widget excluding any window frame
Definition qwidget.h:115
virtual void setVisible(bool visible)
Definition qwidget.cpp:8255
void update()
Updates the widget unless updates are disabled or the widget is hidden.
virtual void changeEvent(QEvent *)
This event handler can be reimplemented to handle state changes.
Definition qwidget.cpp:9382
bool isRightToLeft() const
Definition qwidget.h:419
bool event(QEvent *event) override
This is the main event handler; it handles event event.
Definition qwidget.cpp:8866
QStyle * style() const
Definition qwidget.cpp:2600
virtual void resizeEvent(QResizeEvent *event)
This event handler can be reimplemented in a subclass to receive widget resize events which are passe...
Definition qwidget.cpp:9822
QWidget * parentWidget() const
Returns the parent of this widget, or \nullptr if it does not have any parent widget.
Definition qwidget.h:904
bool isVisible() const
Definition qwidget.h:874
bool visible
whether the widget is visible
Definition qwidget.h:144
QOpenGLWidget * widget
[1]
QString text
QStyleOptionButton opt
Combined button and popup list for selecting options.
@ TopRightCorner
@ TopLeftCorner
@ NoFocus
Definition qnamespace.h:107
@ TabFocus
Definition qnamespace.h:108
@ Key_Tab
Definition qnamespace.h:664
@ Key_Right
Definition qnamespace.h:679
@ Key_Backtab
Definition qnamespace.h:665
@ Key_Left
Definition qnamespace.h:677
@ ShiftModifier
@ ControlModifier
TextElideMode
Definition qnamespace.h:188
constexpr const T & qMax(const T &a, const T &b)
Definition qminmax.h:42
#define SIGNAL(a)
Definition qobjectdefs.h:53
GLenum mode
GLfloat GLfloat GLfloat w
[0]
GLenum GLuint GLintptr GLsizeiptr size
[1]
GLuint index
[2]
GLenum GLenum GLsizei count
GLenum GLenum GLsizei const GLuint GLboolean enabled
GLint GLsizei width
GLuint GLsizei const GLchar * label
[43]
GLboolean enable
GLdouble s
[6]
Definition qopenglext.h:235
GLdouble GLdouble t
Definition qopenglext.h:243
GLdouble GLdouble GLdouble GLdouble q
Definition qopenglext.h:259
GLfloat GLfloat p
[1]
GLuint GLenum option
static qreal position(const QQuickItem *item, QQuickAnchors::Anchor anchorLine)
#define Q_ASSERT(cond)
Definition qrandom.cpp:47
#define zero
QTabBar::Shape _q_tb_tabBarShapeFrom(QTabWidget::TabShape shape, QTabWidget::TabPosition position)
static QSize basicSize(bool horizontal, const QSize &lc, const QSize &rc, const QSize &s, const QSize &t)
#define emit
#define Q_UNUSED(x)
QObject::connect nullptr
myObject disconnect()
[26]
QByteArray page
[45]
QLayoutItem * child
[0]