25#include <QStackedWidget>
27#include <QApplication>
39 m_stack =
new QStackedWidget(
this);
40 m_mainLayout =
new QVBoxLayout;
41 m_mainLayout->setSpacing(0);
42 m_mainLayout->setContentsMargins(0, 0, 0, 0);
44 m_mainLayout->addWidget(m_stack);
45 setLayout(m_mainLayout);
47 connect(m_stack, &QStackedWidget::widgetRemoved,
this, &TabStackedWidget::tabWasRemoved);
62 if (tb->parentWidget() !=
this) {
70 setFocusProxy(m_tabBar);
82 m_tabBar->installEventFilter(
this);
86void TabStackedWidget::tabWasMoved(
int from,
int to)
88 m_stack->blockSignals(
true);
89 QWidget* w = m_stack->widget(from);
90 m_stack->removeWidget(w);
91 m_stack->insertWidget(to, w);
92 m_stack->blockSignals(
false);
95void TabStackedWidget::tabWasRemoved(
int index)
97 if (m_previousIndex == index)
99 else if (m_previousIndex > index)
102 if (m_currentIndex == index)
104 else if (m_currentIndex > index)
112 if (!m_tabBar->isVisible()) {
113 m_dirtyTabBar =
true;
118 m_dirtyTabBar =
false;
123 if (m_dirtyTabBar && obj == m_tabBar && event->type() == QEvent::Show) {
132 if (((event->key() == Qt::Key_Tab || event->key() == Qt::Key_Backtab) &&
133 count() > 1 && event->modifiers() & Qt::ControlModifier)
134#ifdef QT_KEYPAD_NAVIGATION
135 || QApplication::keypadNavigationEnabled() && (event->key() == Qt::Key_Left || event->key() == Qt::Key_Right) &&
count() > 1
138 int pageCount =
count();
140 int dx = (
event->key() == Qt::Key_Backtab ||
event->modifiers() & Qt::ShiftModifier) ? -1 : 1;
141#ifdef QT_KEYPAD_NAVIGATION
142 if (QApplication::keypadNavigationEnabled() && (
event->key() == Qt::Key_Left ||
event->key() == Qt::Key_Right)) {
143 dx =
event->key() == (isRightToLeft() ? Qt::Key_Right : Qt::Key_Left) ? -1 : 1;
146 for (
int pass = 0; pass < pageCount; ++pass) {
149#ifdef QT_KEYPAD_NAVIGATION
150 && !event->isAutoRepeat()
155 else if (page >= pageCount
156#ifdef QT_KEYPAD_NAVIGATION
157 && !event->isAutoRepeat()
167 if (!QApplication::focusWidget()) {
168 m_tabBar->setFocus();
176void TabStackedWidget::showTab(
int index)
178 if (validIndex(index)) {
179 m_stack->setCurrentIndex(index);
182 m_previousIndex = m_currentIndex;
183 m_currentIndex = index;
215 index = m_stack->insertWidget(index, w);
216 m_tabBar->
insertTab(index, QIcon(), label,
true);
220 index = m_stack->insertWidget(index, w);
221 m_tabBar->
insertTab(index, QIcon(), label,
false);
224 if (m_previousIndex >= index)
226 if (m_currentIndex >= index)
236 return m_tabBar->
tabText(index);
256 QWidget*
widget = m_stack->widget(index);
267 m_tabBar->m_blockCurrentChangedSignal =
true;
270 m_stack->removeWidget(
widget);
274 m_tabBar->m_blockCurrentChangedSignal =
false;
287 if (QWidget* w = m_stack->widget(index)) {
291 m_stack->removeWidget(w);
312 return m_stack->currentWidget();
322 return m_stack->widget(index);
327 return m_stack->indexOf(
widget);
332 return m_tabBar->
count();
335bool TabStackedWidget::validIndex(
int index)
const
337 return (index < m_stack->
count() && index >= 0);
340void TabStackedWidget::selectTabOnRemove()
342 Q_ASSERT(
count() > 1);
347 case QTabBar::SelectPreviousTab:
348 if (validIndex(m_previousIndex)) {
349 index = m_previousIndex;
354 case QTabBar::SelectLeftTab:
356 if (!validIndex(index))
360 case QTabBar::SelectRightTab:
362 if (!validIndex(index))
370 Q_ASSERT(validIndex(index));
QTabBar::ButtonPosition iconButtonPosition() const
void tabCloseRequested(int index)
bool documentMode() const
int insertTab(int index, const QString &text)
QString tabText(int index) const
void moveTab(int from, int to)
QTabBar::SelectionBehavior selectionBehaviorOnRemove() const
void removeTab(int index)
QString tabToolTip(int index) const
void setExpanding(bool enabled)
void setElideMode(Qt::TextElideMode elide)
QWidget * tabButton(int index, QTabBar::ButtonPosition position) const
int pinnedTabsCount() const
void setTabButton(int index, QTabBar::ButtonPosition position, QWidget *widget)
void currentChanged(int index)
void setDrawBase(bool drawTheBase)
void overFlowChanged(bool overFlow)
void tabMoved(int from, int to)
void setTabToolTip(int index, const QString &tip)
void setTabText(int index, const QString &text)
bool isTabEnabled(int index) const
bool tabsClosable() const
void setDocumentMode(bool set)
Qt::TextElideMode elideMode() const
void setCurrentIndex(int index)