📄 qtabwidget.cpp
字号:
the behavior is undefined. \sa tabBar()*/void QTabWidget::setTabBar(QTabBar* tb){ Q_D(QTabWidget); Q_ASSERT(tb); if (tb->parentWidget() != this) { tb->setParent(this); tb->show(); } delete d->tabs; d->tabs = tb; setFocusProxy(d->tabs); connect(d->tabs, SIGNAL(currentChanged(int)), this, SLOT(_q_showTab(int))); setUpLayout();}/*! Returns the current QTabBar. \sa setTabBar()*/QTabBar* QTabWidget::tabBar() const{ Q_D(const QTabWidget); return d->tabs;}/*! Ensures that the selected tab's page is visible and appropriately sized.*/void QTabWidgetPrivate::_q_showTab(int index){ Q_Q(QTabWidget); if (index < stack->count() && index >= 0) { stack->setCurrentIndex(index); emit q->currentChanged(index);#ifdef QT3_SUPPORT emit q->currentChanged(stack->widget(index));#endif }}void QTabWidgetPrivate::_q_removeTab(int index){ Q_Q(QTabWidget); tabs->removeTab(index); q->setUpLayout(); q->tabRemoved(index);}/* Set up the layout. Get subrect from the current style, and set the geometry for the stack widget, tab bar and corner widgets.*/void QTabWidget::setUpLayout(bool onlyCheck){ Q_D(QTabWidget); if (onlyCheck && !d->dirty) return; // nothing to do if (!isVisible()) { d->dirty = true; return; // we'll do it later } QStyleOptionTabWidgetFrame option = d->getStyleOption(); QRect tabRect = style()->subElementRect(QStyle::SE_TabWidgetTabBar, &option, this); d->panelRect = style()->subElementRect(QStyle::SE_TabWidgetTabPane, &option, this); QRect contentsRect = style()->subElementRect(QStyle::SE_TabWidgetTabContents, &option, this); QRect leftCornerRect = style()->subElementRect(QStyle::SE_TabWidgetLeftCorner, &option, this); QRect rightCornerRect = style()->subElementRect(QStyle::SE_TabWidgetRightCorner, &option, this); d->tabs->setGeometry(tabRect); d->stack->setGeometry(contentsRect); if (d->leftCornerWidget) d->leftCornerWidget->setGeometry(leftCornerRect); if (d->rightCornerWidget) d->rightCornerWidget->setGeometry(rightCornerRect); if (!onlyCheck) update(); updateGeometry();}/*! \reimp*/QSize QTabWidget::sizeHint() const{ Q_D(const QTabWidget); QSize lc(0, 0), rc(0, 0); QStyleOption opt(0); opt.init(this); opt.state = QStyle::State_None; if (d->leftCornerWidget) lc = d->leftCornerWidget->sizeHint(); if(d->rightCornerWidget) rc = d->rightCornerWidget->sizeHint(); if (!d->dirty) { QTabWidget *that = (QTabWidget*)this; that->setUpLayout(true); } QSize s(d->stack->sizeHint()); QSize t(d->tabs->sizeHint()); if(!style()->styleHint(QStyle::SH_TabBar_PreferNoArrows, &opt, d->tabs)) t = t.boundedTo(QSize(200,200)); else t = t.boundedTo(QApplication::desktop()->size()); QSize sz; if (d->pos == North || d->pos == South) sz = QSize(qMax(s.width(), t.width() + rc.width() + lc.width()), s.height() + (qMax(rc.height(), qMax(lc.height(), t.height())))); else sz = QSize(s.width() + (qMax(rc.width(), qMax(lc.width(), t.width()))), qMax(s.height(), t.height() + rc.height() + lc.height())); return style()->sizeFromContents(QStyle::CT_TabWidget, &opt, sz, this) .expandedTo(QApplication::globalStrut());}/*! \reimp Returns a suitable minimum size for the tab widget.*/QSize QTabWidget::minimumSizeHint() const{ Q_D(const QTabWidget); QSize lc(0, 0), rc(0, 0); if(d->leftCornerWidget) lc = d->leftCornerWidget->minimumSizeHint(); if(d->rightCornerWidget) rc = d->rightCornerWidget->minimumSizeHint(); if (!d->dirty) { QTabWidget *that = (QTabWidget*)this; that->setUpLayout(true); } QSize s(d->stack->minimumSizeHint()); QSize t(d->tabs->minimumSizeHint()); QSize sz(qMax(s.width(), t.width() + rc.width() + lc.width()), s.height() + (qMax(rc.height(), qMax(lc.height(), t.height())))); QStyleOption opt(0); opt.rect = rect(); opt.palette = palette(); opt.state = QStyle::State_None; return style()->sizeFromContents(QStyle::CT_TabWidget, &opt, sz, this) .expandedTo(QApplication::globalStrut());}/*! \reimp */void QTabWidget::showEvent(QShowEvent *){ setUpLayout();}void QTabWidgetPrivate::updateTabBarPosition(){ Q_Q(QTabWidget); switch (pos) { case QTabWidget::North: tabs->setShape(shape == QTabWidget::Rounded ? QTabBar::RoundedNorth : QTabBar::TriangularNorth); break; case QTabWidget::South: tabs->setShape(shape == QTabWidget::Rounded ? QTabBar::RoundedSouth : QTabBar::TriangularSouth); break; case QTabWidget::West: tabs->setShape(shape == QTabWidget::Rounded ? QTabBar::RoundedWest : QTabBar::TriangularWest); break; case QTabWidget::East: tabs->setShape(shape == QTabWidget::Rounded ? QTabBar::RoundedEast : QTabBar::TriangularEast); break; } q->setUpLayout();}/*! \property QTabWidget::tabPosition \brief the position of the tabs in this tab widget Possible values for this property are described by the TabPosition enum. \sa TabPosition*/QTabWidget::TabPosition QTabWidget::tabPosition() const{ Q_D(const QTabWidget); return d->pos;}void QTabWidget::setTabPosition(TabPosition pos){ Q_D(QTabWidget); if (d->pos == pos) return; d->pos = pos; d->updateTabBarPosition();}/*! \property QTabWidget::tabShape \brief the shape of the tabs in this tab widget Possible values for this property are QTabWidget::Rounded (default) or QTabWidget::Triangular. \sa TabShape*/QTabWidget::TabShape QTabWidget::tabShape() const{ Q_D(const QTabWidget); return d->shape;}void QTabWidget::setTabShape(TabShape s){ Q_D(QTabWidget); if (d->shape == s) return; d->shape = s; d->updateTabBarPosition();}/*! \reimp */bool QTabWidget::event(QEvent *ev){ if (ev->type() == QEvent::LayoutRequest) setUpLayout(); return QWidget::event(ev);}/*! \reimp */void QTabWidget::changeEvent(QEvent *ev){ if(ev->type() == QEvent::StyleChange) setUpLayout(); QWidget::changeEvent(ev);}/*! \reimp */void QTabWidget::keyPressEvent(QKeyEvent *e){ Q_D(QTabWidget); if ((e->key() == Qt::Key_Tab || e->key() == Qt::Key_Backtab) && count() > 1 && e->modifiers() & Qt::ControlModifier) { int page = currentIndex(); if (e->key() == Qt::Key_Backtab || e->modifiers() & Qt::ShiftModifier) { page--; if (page < 0) page = count() - 1; } else { page++; if (page >= count()) page = 0; } setCurrentIndex(page); if (!qApp->focusWidget()) d->tabs->setFocus(); } else { e->ignore(); }}/*! Returns the tab page at index position \a index or 0 if the \a index is out of range.*/QWidget *QTabWidget::widget(int index) const{ Q_D(const QTabWidget); return d->stack->widget(index);}/*! \property QTabWidget::count \brief the number of tabs in the tab bar*/int QTabWidget::count() const{ Q_D(const QTabWidget); return d->tabs->count();}#ifndef QT_NO_TOOLTIP/*! Sets the tab tool tip for the page at position \a index to \a tip. \sa tabToolTip()*/void QTabWidget::setTabToolTip(int index, const QString & tip){ Q_D(QTabWidget); d->tabs->setTabToolTip(index, tip);}/*! Returns the tab tool tip for the page at position \a index or an empty string if no tool tip has been set. \sa setTabToolTip()*/QString QTabWidget::tabToolTip(int index) const{ Q_D(const QTabWidget); return d->tabs->tabToolTip(index);}#endif // QT_NO_TOOLTIP#ifndef QT_NO_WHATSTHIS/*! \since 4.1 Sets the What's This help text for the page at position \a index to \a text.*/void QTabWidget::setTabWhatsThis(int index, const QString &text){ Q_D(QTabWidget); d->tabs->setTabWhatsThis(index, text);}/*! \since 4.1 Returns the What's This help text for the page at position \a index, or an empty string if no help text has been set.*/QString QTabWidget::tabWhatsThis(int index) const{ Q_D(const QTabWidget); return d->tabs->tabWhatsThis(index);}#endif // QT_NO_WHATSTHIS/*! This virtual handler is called after a new tab was added or inserted at position \a index. \sa tabRemoved() */void QTabWidget::tabInserted(int index){ Q_UNUSED(index)}/*! This virtual handler is called after a tab was removed from position \a index. \sa tabInserted() */void QTabWidget::tabRemoved(int index){ Q_UNUSED(index)}/*! \fn void QTabWidget::paintEvent(QPaintEvent *event) Paints the tab widget's tab bar in response to the paint \a event.*/void QTabWidget::paintEvent(QPaintEvent *){ Q_D(QTabWidget); QStylePainter p(this); QStyleOptionTabWidgetFrame opt; opt = d->getStyleOption(); opt.rect = d->panelRect; p.drawPrimitive(QStyle::PE_FrameTabWidget, opt);}/*! \fn void QTabWidget::insertTab(QWidget * widget, const QString &label, int index) Use insertTab(index, widget, label) instead.*//*! \fn void QTabWidget::insertTab(QWidget *widget, const QIcon& icon, const QString &label, int index) Use insertTab(index, widget, icon, label) instead.*//*! \fn void QTabWidget::changeTab(QWidget *widget, const QString &label) Use setTabText() instead.*//*! \fn void QTabWidget::changeTab(QWidget *widget, const QIcon& icon, const QString &label) Use setTabText() and setTabIcon() instead.*//*! \fn bool QTabWidget::isTabEnabled( QWidget *widget) const Use isTabEnabled(tabWidget->indexOf(widget)) instead.*//*! \fn void QTabWidget::setTabEnabled(QWidget *widget, bool b) Use isTabEnabled(tabWidget->indexOf(widget), b) instead.*//*! \fn QString QTabWidget::tabLabel(QWidget *widget) const Use tabText(tabWidget->indexOf(widget)) instead.*//*! \fn void QTabWidget::setTabLabel(QWidget *widget, const QString &label) Use setTabText(tabWidget->indexOf(widget), label) instead.*//*! \fn QIcon QTabWidget::tabIconSet(QWidget * widget) const Use tabIcon(tabWidget->indexOf(widget)) instead.*//*! \fn void QTabWidget::setTabIconSet(QWidget * widget, const QIcon & icon) Use setTabIcon(tabWidget->indexOf(widget), icon) instead.*//*! \fn void QTabWidget::removeTabToolTip(QWidget * widget) Use setTabToolTip(tabWidget->indexOf(widget), QString()) instead.*//*! \fn void QTabWidget::setTabToolTip(QWidget * widget, const QString & tip) Use setTabToolTip(tabWidget->indexOf(widget), tip) instead.*//*! \fn QString QTabWidget::tabToolTip(QWidget * widget) const Use tabToolTip(tabWidget->indexOf(widget)) instead.*//*! \fn QWidget * QTabWidget::currentPage() const Use currentWidget() instead.*//*! \fn QWidget *QTabWidget::page(int index) const Use widget() instead.*//*! \fn QString QTabWidget::label(int index) const Use tabText() instead.*//*! \fn int QTabWidget::currentPageIndex() const Use currentIndex() instead.*//*! \fn int QTabWidget::margin() const This function is kept only to make old code compile. This functionality is no longer supported by QTabWidget. \sa contentsRect(), setContentsMargins()*//*! \fn void QTabWidget::setMargin(int margin) This function is kept only to make old code compile. This functionality is no longer supported by QTabWidget. \sa contentsRect(), setContentsMargins()*//*! \fn void QTabWidget::setCurrentPage(int index) Use setCurrentIndex() instead.*//*! \fn void QTabWidget::showPage(QWidget *widget) Use setCurrentIndex(indexOf(widget)) instead.*//*! \fn void QTabWidget::removePage(QWidget *widget) Use removeTab(indexOf(widget)) instead.*//*! \fn void QTabWidget::currentChanged(QWidget *widget) Use currentChanged(int) instead.*/#include "moc_qtabwidget.cpp"#endif //QT_NO_TABWIDGET
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -