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

📄 qtabbar.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 3 页
字号:
        } else if (sender == rightB) {            int availableWidth = q->width() - extraWidth();            for (i = 0; i < tabList.count(); ++i) {                if (tabList.at(i).rect.right() - scrollOffset > availableWidth) {                    makeVisible(i);                    return;                }            }        }    } else { // vertical        if (sender == leftB) {            for (i = tabList.count() - 1; i >= 0; --i) {                if (tabList.at(i).rect.top() - scrollOffset < 0) {                    makeVisible(i);                    return;                }            }        } else if (sender == rightB) {            int available = q->height() - extraWidth();            for (i = 0; i < tabList.count(); ++i) {                if (tabList.at(i).rect.bottom() - scrollOffset > available) {                    makeVisible(i);                    return;                }            }        }    }}void QTabBarPrivate::refresh(){    Q_Q(QTabBar);    if (!q->isVisible()) {        layoutDirty = true;    } else {        layoutTabs();        makeVisible(currentIndex);        q->update();        q->updateGeometry();    }}/*!    Creates a new tab bar with the given \a parent.*/QTabBar::QTabBar(QWidget* parent)    :QWidget(*new QTabBarPrivate, parent, 0){    Q_D(QTabBar);    d->init();}/*!    Destroys the tab bar.*/QTabBar::~QTabBar(){}/*!    \property QTabBar::shape    \brief the shape of the tabs in the tab bar    Possible values for this property are described by the Shape enum.*/QTabBar::Shape QTabBar::shape() const{    Q_D(const QTabBar);    return d->shape;}void QTabBar::setShape(Shape shape){    Q_D(QTabBar);    if (d->shape == shape)        return;    d->shape = shape;    d->refresh();}/*!    \property QTabBar::drawBase    \brief defines whether or not tab bar should draw its base.    If true then QTabBar draws a base in relation to the styles overlab.    Otherwise only the tabs are drawn.    \sa QStyle::pixelMetric() QStyle::PM_TabBarBaseOverlap QStyleOptionTabBarBase*/void QTabBar::setDrawBase(bool drawBase){    Q_D(QTabBar);    d->drawBase = drawBase;}bool QTabBar::drawBase() const{    Q_D(const QTabBar);    return d->drawBase;}/*!    Adds a new tab with text \a text. Returns the new    tab's index.*/int QTabBar::addTab(const QString &text){    return insertTab(-1, text);}/*!    \overload    Adds a new tab with icon \a icon and text \a    text. Returns the new tab's index.*/int QTabBar::addTab(const QIcon& icon, const QString &text){    return insertTab(-1, icon, text);}/*!    Inserts a new tab with text \a text at position \a index. If \a    index is out of range, the new tab is appened. Returns the new    tab's index.*/int QTabBar::insertTab(int index, const QString &text){    return insertTab(index, QIcon(), text);}/*!\overload    Inserts a new tab with icon \a icon and text \a text at position    \a index. If \a index is out of range, the new tab is    appended. Returns the new tab's index.    If the QTabBar was empty before this function is called, the inserted tab    becomes the current tab.    Inserting a new tab at an index less than or equal to the current index    will increment the current index, but keep the current tab.*/int QTabBar::insertTab(int index, const QIcon& icon, const QString &text){    Q_D(QTabBar);    if (!d->validIndex(index)) {        index = d->tabList.count();        d->tabList.append(QTabBarPrivate::Tab(icon, text));    } else {        d->tabList.insert(index, QTabBarPrivate::Tab(icon, text));    }#ifndef QT_NO_SHORTCUT    d->tabList[index].shortcutId = grabShortcut(QKeySequence::mnemonic(text));#endif    d->refresh();    if (d->tabList.count() == 1)        setCurrentIndex(index);    else if (index <= d->currentIndex)        ++d->currentIndex;    tabInserted(index);    return index;}/*!    Removes the tab at position \a index. */void QTabBar::removeTab(int index){    Q_D(QTabBar);    if (d->validIndex(index)) {#ifndef QT_NO_SHORTCUT        releaseShortcut(d->tabList.at(index).shortcutId);#endif        d->tabList.removeAt(index);        if (index == d->currentIndex) {            // The current tab is going away, in order to make sure            // we emit that "current has changed", we need to reset this            // around.            d->currentIndex = -1;            if (index == d->tabList.size()) {                setCurrentIndex(d->validIndex(index - 1) ? index - 1 : 0);            } else {                setCurrentIndex(d->validIndex(index) ? index : 0);            }        } else if (index < d->currentIndex) {            setCurrentIndex(d->currentIndex - 1);        }        d->refresh();        tabRemoved(index);    }}/*!    Returns true if the tab at position \a index is enabled; otherwise    returns false.*/bool QTabBar::isTabEnabled(int index) const{    Q_D(const QTabBar);    if (const QTabBarPrivate::Tab *tab = d->at(index))        return tab->enabled;    return false;}/*!    If \a enabled is true then the tab at position \a index is    enabled; otherwise the item at position \a index is disabled.*/void QTabBar::setTabEnabled(int index, bool enabled){    Q_D(QTabBar);    if (QTabBarPrivate::Tab *tab = d->at(index)) {        tab->enabled = enabled;#ifndef QT_NO_SHORTCUT        setShortcutEnabled(tab->shortcutId, enabled);#endif        update();        if (!enabled && index == d->currentIndex)            setCurrentIndex(d->validIndex(index+1)?index+1:0);        else if (enabled && !d->validIndex(d->currentIndex))            setCurrentIndex(index);    }}/*!    Returns the text of the tab at position \a index, or an empty    string if \a index is out of range.*/QString QTabBar::tabText(int index) const{    Q_D(const QTabBar);    if (const QTabBarPrivate::Tab *tab = d->at(index))        return tab->text;    return QString();}/*!    Sets the text of the tab at position \a index to \a text.*/void QTabBar::setTabText(int index, const QString &text){    Q_D(QTabBar);    if (QTabBarPrivate::Tab *tab = d->at(index)) {        tab->text = text;#ifndef QT_NO_SHORTCUT        releaseShortcut(tab->shortcutId);        tab->shortcutId = grabShortcut(QKeySequence::mnemonic(text));        setShortcutEnabled(tab->shortcutId, tab->enabled);#endif        d->refresh();    }}/*!    Returns the text color of the tab with the given \a index, or a invalid    color if \a index is out of range.    \sa setTabTextColor()*/QColor QTabBar::tabTextColor(int index) const{    Q_D(const QTabBar);    if (const QTabBarPrivate::Tab *tab = d->at(index))        return tab->textColor;    return QColor();}/*!    Sets the color of the text in the tab with the given \a index to the specified \a color.    If an invalid color is specified, the tab will use the QTabBar foreground role instead.    \sa tabTextColor()*/void QTabBar::setTabTextColor(int index, const QColor &color){    Q_D(QTabBar);    if (QTabBarPrivate::Tab *tab = d->at(index)) {        tab->textColor = color;        update(tabRect(index));    }}/*!    Returns the icon of the tab at position \a index, or a null icon    if \a index is out of range.*/QIcon QTabBar::tabIcon(int index) const{    Q_D(const QTabBar);    if (const QTabBarPrivate::Tab *tab = d->at(index))        return tab->icon;    return QIcon();}/*!    Sets the icon of the tab at position \a index to \a icon.*/void QTabBar::setTabIcon(int index, const QIcon & icon){    Q_D(QTabBar);    if (QTabBarPrivate::Tab *tab = d->at(index)) {        bool simpleIconChange = (!icon.isNull() && !tab->icon.isNull());        tab->icon = icon;        if (simpleIconChange)            update(tabRect(index));        else            d->refresh();    }}#ifndef QT_NO_TOOLTIP/*!    Sets the tool tip of the tab at position \a index to \a tip.*/void QTabBar::setTabToolTip(int index, const QString & tip){    Q_D(QTabBar);    if (QTabBarPrivate::Tab *tab = d->at(index))        tab->toolTip = tip;}/*!    Returns the tool tip of the tab at position \a index, or an empty    string if \a index is out of range.*/QString QTabBar::tabToolTip(int index) const{    Q_D(const QTabBar);    if (const QTabBarPrivate::Tab *tab = d->at(index))        return tab->toolTip;    return QString();}#endif // QT_NO_TOOLTIP#ifndef QT_NO_WHATSTHIS/*!    \since 4.1    Sets the What's This help text of the tab at position \a index    to \a text.*/void QTabBar::setTabWhatsThis(int index, const QString &text){    Q_D(QTabBar);    if (QTabBarPrivate::Tab *tab = d->at(index))        tab->whatsThis = text;}/*!    \since 4.1    Returns the What's This help text of the tab at position \a index,    or an empty string if \a index is out of range.*/QString QTabBar::tabWhatsThis(int index) const{    Q_D(const QTabBar);    if (const QTabBarPrivate::Tab *tab = d->at(index))        return tab->whatsThis;    return QString();}#endif // QT_NO_WHATSTHIS/*!    Sets the data of the tab at position \a index to \a data.*/void QTabBar::setTabData(int index, const QVariant & data){    Q_D(QTabBar);    if (QTabBarPrivate::Tab *tab = d->at(index))        tab->data = data;}/*!    Returns the datad of the tab at position \a index, or a null    variant if \a index is out of range.*/QVariant QTabBar::tabData(int index) const{    Q_D(const QTabBar);    if (const QTabBarPrivate::Tab *tab = d->at(index))        return tab->data;    return QVariant();}/*!    Returns the visual rectangle of the of the tab at position \a    index, or a null rectangle if \a index is out of range.*/QRect QTabBar::tabRect(int index) const{    Q_D(const QTabBar);    if (const QTabBarPrivate::Tab *tab = d->at(index)) {        if (d->layoutDirty)            const_cast<QTabBarPrivate*>(d)->layoutTabs();        QRect r = tab->rect;        if (verticalTabs(d->shape))            r.translate(0, -d->scrollOffset);        else            r.translate(-d->scrollOffset, 0);        return QStyle::visualRect(layoutDirection(), rect(), r);    }    return QRect();}/*!    \since 4.3    Returns the index of the tab that covers \a position or -1 if no    tab covers \a position;*/int QTabBar::tabAt(const QPoint &position) const{    Q_D(const QTabBar);    if (d->validIndex(d->currentIndex)        && tabRect(d->currentIndex).contains(position)) {        return d->currentIndex;    }    const int max = d->tabList.size();    for (int i = 0; i < max; ++i) {        if (tabRect(i).contains(position)) {            return i;        }    }    return -1;}/*!    \property QTabBar::currentIndex    \brief the index of the tab bar's visible tab*/int QTabBar::currentIndex() const{    Q_D(const QTabBar);    if (d->validIndex(d->currentIndex))        return d->currentIndex;    return -1;}void QTabBar::setCurrentIndex(int index){    Q_D(QTabBar);    if (d->validIndex(index) && d->currentIndex != index) {        d->currentIndex = index;        update();        d->makeVisible(index);#ifdef QT3_SUPPORT        emit selected(index);#endif        emit currentChanged(index);    }}/*!    \property QTabBar::iconSize    \brief The size for icons in the tab bar    \since 4.1    The default value is style-dependent. \c iconSize is a maximum    size; icons that are smaller are not scaled up.    \sa QTabWidget::iconSize*/QSize QTabBar::iconSize() const{    Q_D(const QTabBar);    if (d->iconSize.isValid())        return d->iconSize;

⌨️ 快捷键说明

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