summaryrefslogtreecommitdiffstats
path: root/src/widgets/widgets/qtabwidget.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/widgets/widgets/qtabwidget.cpp')
-rw-r--r--src/widgets/widgets/qtabwidget.cpp62
1 files changed, 53 insertions, 9 deletions
diff --git a/src/widgets/widgets/qtabwidget.cpp b/src/widgets/widgets/qtabwidget.cpp
index 4d7b39ae01..f0bfe67e3a 100644
--- a/src/widgets/widgets/qtabwidget.cpp
+++ b/src/widgets/widgets/qtabwidget.cpp
@@ -215,9 +215,9 @@ public:
};
QTabWidgetPrivate::QTabWidgetPrivate()
- : tabs(0), stack(0), dirty(true),
+ : tabs(nullptr), stack(nullptr), dirty(true),
pos(QTabWidget::North), shape(QTabWidget::Rounded),
- leftCornerWidget(0), rightCornerWidget(0)
+ leftCornerWidget(nullptr), rightCornerWidget(nullptr)
{}
QTabWidgetPrivate::~QTabWidgetPrivate()
@@ -249,7 +249,7 @@ void QTabWidgetPrivate::init()
q->setFocusPolicy(Qt::TabFocus);
q->setFocusProxy(tabs);
q->setTabPosition(static_cast<QTabWidget::TabPosition> (q->style()->styleHint(
- QStyle::SH_TabWidget_DefaultTabPosition, 0, q )));
+ QStyle::SH_TabWidget_DefaultTabPosition, nullptr, q )));
}
@@ -280,7 +280,7 @@ void QTabWidgetPrivate::initBasicStyleOption(QStyleOptionTabWidgetFrame *option)
if (q->documentMode())
option->lineWidth = 0;
else
- option->lineWidth = q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, 0, q);
+ option->lineWidth = q->style()->pixelMetric(QStyle::PM_DefaultFrameWidth, nullptr, q);
switch (pos) {
case QTabWidget::North:
@@ -319,7 +319,7 @@ void QTabWidget::initStyleOption(QStyleOptionTabWidgetFrame *option) const
Q_D(const QTabWidget);
d->initBasicStyleOption(option);
- int exth = style()->pixelMetric(QStyle::PM_TabBarBaseHeight, 0, this);
+ int exth = style()->pixelMetric(QStyle::PM_TabBarBaseHeight, nullptr, this);
QSize t(0, d->stack->frameWidth());
if (d->tabs->isVisibleTo(const_cast<QTabWidget *>(this))) {
t = d->tabs->sizeHint();
@@ -359,7 +359,7 @@ void QTabWidget::initStyleOption(QStyleOptionTabWidgetFrame *option) const
Constructs a tabbed widget with parent \a parent.
*/
QTabWidget::QTabWidget(QWidget *parent)
- : QWidget(*new QTabWidgetPrivate, parent, 0)
+ : QWidget(*new QTabWidgetPrivate, parent, { })
{
Q_D(QTabWidget);
d->init();
@@ -544,8 +544,8 @@ bool QTabWidget::isTabEnabled(int index) const
}
/*!
- If \a enable is true, the page at position \a index is enabled; otherwise the page at position \a index is
- disabled. The page's tab is redrawn appropriately.
+ If \a enable is true, the page at position \a index is enabled; otherwise the page at
+ position \a index is disabled. The page's tab is redrawn appropriately.
QTabWidget uses QWidget::setEnabled() internally, rather than
keeping a separate flag.
@@ -566,6 +566,44 @@ void QTabWidget::setTabEnabled(int index, bool enable)
}
/*!
+ Returns true if the page at position \a index is visible; otherwise returns false.
+
+ \sa setTabVisible()
+ \since 5.15
+*/
+
+bool QTabWidget::isTabVisible(int index) const
+{
+ Q_D(const QTabWidget);
+ return d->tabs->isTabVisible(index);
+}
+
+/*!
+ If \a visible is true, the page at position \a index is visible; otherwise the page at
+ position \a index is hidden. The page's tab is redrawn appropriately.
+
+ \sa isTabVisible()
+ \since 5.15
+*/
+
+void QTabWidget::setTabVisible(int index, bool visible)
+{
+ Q_D(QTabWidget);
+ QWidget *widget = d->stack->widget(index);
+ bool currentVisible = d->tabs->isTabVisible(d->tabs->currentIndex());
+ d->tabs->setTabVisible(index, visible);
+ if (!visible) {
+ if (widget)
+ widget->setVisible(false);
+ } else if (!currentVisible) {
+ setCurrentIndex(index);
+ if (widget)
+ widget->setVisible(true);
+ }
+ setUpLayout();
+}
+
+/*!
\fn void QTabWidget::setCornerWidget(QWidget *widget, Qt::Corner corner)
Sets the given \a widget to be shown in the specified \a corner of the
@@ -848,7 +886,13 @@ QSize QTabWidget::sizeHint() const
QTabWidget *that = const_cast<QTabWidget*>(this);
that->setUpLayout(true);
}
- QSize s(d->stack->sizeHint());
+ QSize s;
+ for (int i=0; i< d->stack->count(); ++i) {
+ if (const QWidget* w = d->stack->widget(i)) {
+ if (d->tabs->isTabVisible(i))
+ s = s.expandedTo(w->sizeHint());
+ }
+ }
QSize t;
if (!d->isAutoHidden()) {
t = d->tabs->sizeHint();