⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 qtabwidget.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
{    Q_D(QTabWidget);    d->tabs->setTabText(index, label);    setUpLayout();}/*!    Returns the label text for the tab on the page at position \a index.*/QString QTabWidget::tabText(int index) const{    Q_D(const QTabWidget);    return d->tabs->tabText(index);}/*!    \overload    Sets the \a icon for the tab at position \a index.*/void QTabWidget::setTabIcon(int index, const QIcon &icon){    Q_D(QTabWidget);    d->tabs->setTabIcon(index, icon);    setUpLayout();}/*!    Returns the icon for the tab on the page at position \a index.*/QIcon QTabWidget::tabIcon(int index) const{    Q_D(const QTabWidget);    return d->tabs->tabIcon(index);}/*!    Returns true if the the page at position \a index is enabled; otherwise returns false.    \sa setTabEnabled(), QWidget::isEnabled()*/bool QTabWidget::isTabEnabled(int index) const{    Q_D(const QTabWidget);    return d->tabs->isTabEnabled(index);}/*!    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.    Note that even a disabled tab/page may be visible. If the page is    visible already, QTabWidget will not hide it; if all the pages are    disabled, QTabWidget will show one of them.    \sa isTabEnabled(), QWidget::setEnabled()*/void QTabWidget::setTabEnabled(int index, bool enable){    Q_D(QTabWidget);    d->tabs->setTabEnabled(index, enable);}/*!  \fn void QTabWidget::setCornerWidget(QWidget *widget, Qt::Corner corner)  Sets the given \a widget to be shown in the specified \a corner of the  tab widget. The geometry of the widget is determined based on the widget's  sizeHint() and the style().  Only the horizontal element of the \a corner will be used.  Passing 0 shows no widget in the corner.  Any previously set corner widget is hidden.  All widgets set here will be deleted by the tab widget when it is  destroyed unless you separately reparent the widget after setting  some other corner widget (or 0).  Note: Corner widgets are designed for \l North and \l South tab positions;  other orientations are known to not work properly.  \sa cornerWidget(), setTabPosition()*/void QTabWidget::setCornerWidget(QWidget * widget, Qt::Corner corner){    Q_D(QTabWidget);    if (widget && widget->parentWidget() != this)        widget->setParent(this);    if (corner & Qt::TopRightCorner) {        if (d->rightCornerWidget)            d->rightCornerWidget->hide();        d->rightCornerWidget = widget;    } else {        if (d->leftCornerWidget)            d->leftCornerWidget->hide();        d->leftCornerWidget = widget;    }    setUpLayout();}/*!    Returns the widget shown in the \a corner of the tab widget or 0.*/QWidget * QTabWidget::cornerWidget(Qt::Corner corner) const{    Q_D(const QTabWidget);    if (corner & Qt::TopRightCorner)        return d->rightCornerWidget;    return d->leftCornerWidget;}/*!   Removes the tab at position \a index from this stack of widgets.   The page widget itself is not deleted.   \sa addTab(), insertTab()*/void QTabWidget::removeTab(int index){    Q_D(QTabWidget);    if (QWidget *w = d->stack->widget(index))        d->stack->removeWidget(w);}/*!    Returns a pointer to the page currently being displayed by the tab    dialog. The tab dialog does its best to make sure that this value    is never 0 (but if you try hard enough, it can be).    \sa currentIndex(), setCurrentWidget()*/QWidget * QTabWidget::currentWidget() const{    Q_D(const QTabWidget);    return d->stack->currentWidget();}/*!    Makes \a widget the current widget. The \a widget used must be a page in    this tab widget.    \sa addTab(), setCurrentIndex(), currentWidget() */void QTabWidget::setCurrentWidget(QWidget *widget){    Q_D(const QTabWidget);    d->tabs->setCurrentIndex(indexOf(widget));}/*!    \property QTabWidget::currentIndex    \brief the index position of the current tab page*/int QTabWidget::currentIndex() const{    Q_D(const QTabWidget);    return d->tabs->currentIndex();}void QTabWidget::setCurrentIndex(int index){    Q_D(QTabWidget);    d->tabs->setCurrentIndex(index);}/*!    Returns the index position of the page occupied by the widget \a    w, or -1 if the widget cannot be found.*/int QTabWidget::indexOf(QWidget* w) const{    Q_D(const QTabWidget);    return d->stack->indexOf(w);}/*!    \reimp*/void QTabWidget::resizeEvent(QResizeEvent *e){    QWidget::resizeEvent(e);    setUpLayout();}/*!    Replaces the dialog's QTabBar heading with the tab bar \a tb. Note    that this must be called \e before any tabs have been added, or    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->selected(q->tabText(index));        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    QStyleOptionTabWidgetFrame option;    initStyleOption(&option);    // this must be done immediately, because QWidgetItem relies on it (even if !isVisible())    d->setLayoutItemMargins(QStyle::SE_TabWidgetLayoutItem, &option);    if (!isVisible()) {        d->dirty = true;        return; // we'll do it later    }    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(usesScrollButtons())        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

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -