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

📄 qtoolbox.cpp

📁 奇趣公司比较新的qt/emd版本
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    Q_Q(QToolBox);    QToolBoxButton *tb = ::qobject_cast<QToolBoxButton*>(q->sender());    QWidget* item = 0;    for (QToolBoxPrivate::PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i)        if ((*i).button == tb) {            item = (*i).widget;            break;        }    q->setCurrentIndex(q->indexOf(item));}/*!    \property QToolBox::count    \brief The number of items contained in the toolbox.*/int QToolBox::count() const{    Q_D(const QToolBox);    return d->pageList.count();}void QToolBox::setCurrentIndex(int index){    Q_D(QToolBox);    QToolBoxPrivate::Page *c = d->page(index);    if (!c || d->currentPage == c)        return;    c->button->setSelected(true);    if (d->currentPage) {        d->currentPage->sv->hide();        d->currentPage->button->setSelected(false);    }    d->currentPage = c;    d->currentPage->sv->show();    d->updateTabs();    emit currentChanged(index);}void QToolBoxPrivate::relayout(){    Q_Q(QToolBox);    delete layout;    layout = new QVBoxLayout(q);    for (QToolBoxPrivate::PageList::ConstIterator i = pageList.constBegin(); i != pageList.constEnd(); ++i) {        layout->addWidget((*i).button);        layout->addWidget((*i).sv);    }}void QToolBoxPrivate::_q_widgetDestroyed(QObject *object){    Q_Q(QToolBox);    // no verification - vtbl corrupted already    QWidget *p = (QWidget*)object;    QToolBoxPrivate::Page *c = page(p);    if (!p || !c)        return;    layout->removeWidget(c->sv);    layout->removeWidget(c->button);    c->sv->deleteLater(); // page might still be a child of sv    delete c->button;    bool removeCurrent = c == currentPage;    pageList.removeAll(*c);    if (!pageList.count()) {        currentPage = 0;        emit q->currentChanged(-1);    } else if (removeCurrent) {        currentPage = 0;        q->setCurrentIndex(0);    }}/*!    Removes the item at position \a index from the toolbox. Note that    the widget is \e not deleted.*/void QToolBox::removeItem(int index){    Q_D(QToolBox);    if (QWidget *w = widget(index)) {        disconnect(w, SIGNAL(destroyed(QObject*)), this, SLOT(_q_widgetDestroyed(QObject*)));        w->setParent(this);        // destroy internal data        d->_q_widgetDestroyed(w);        itemRemoved(index);    }}/*!    \property QToolBox::currentIndex    \brief The index of the current item, or -1 if the toolbox is empty.    \sa indexOf(), widget()*/int QToolBox::currentIndex() const{    Q_D(const QToolBox);    return d->currentPage ? indexOf(d->currentPage->widget) : -1;}/*!    Returns a pointer to the current widget, or 0 if there is no such item.    \sa currentIndex(), setCurrentWidget()*/QWidget * QToolBox::currentWidget() const{    Q_D(const QToolBox);    return d->currentPage ? d->currentPage->widget : 0;}/*!  Makes\a widget the current widget. The \a widget must be an item in this tool box.  \sa addItem(), setCurrentIndex(), currentWidget() */void QToolBox::setCurrentWidget(QWidget *widget){    int i = indexOf(widget);    if (i >= 0)        setCurrentIndex(i);    else        qWarning("QToolBox::setCurrentWidget: widget not contained in tool box");}/*!    Returns the widget at position \a index, or 0 if there is no such    item.*/QWidget *QToolBox::widget(int index) const{    Q_D(const QToolBox);    if (index < 0 || index >= (int) d->pageList.size())        return 0;    return d->pageList.at(index).widget;}/*!    Returns the index of \a widget, or -1 if the item does not    exist.*/int QToolBox::indexOf(QWidget *widget) const{    Q_D(const QToolBox);    QToolBoxPrivate::Page *c = (widget ? d->page(widget) : 0);    return c ? d->pageList.indexOf(*c) : -1;}/*!    If \a enabled is true then the item at position \a index is enabled; otherwise    the item at position \a index is disabled.*/void QToolBox::setItemEnabled(int index, bool enabled){    Q_D(QToolBox);    QToolBoxPrivate::Page *c = d->page(index);    if (!c)        return;    c->button->setEnabled(enabled);    if (!enabled && c == d->currentPage) {        int curIndexUp = index;        int curIndexDown = curIndexUp;        const int count = d->pageList.count();        while (curIndexUp > 0 || curIndexDown < count-1) {            if (curIndexDown < count-1) {                if (d->page(++curIndexDown)->button->isEnabled()) {                    index = curIndexDown;                    break;                }            }            if (curIndexUp > 0) {                if (d->page(--curIndexUp)->button->isEnabled()) {                    index = curIndexUp;                    break;                }            }        }        setCurrentIndex(index);    }}/*!    Sets the text of the item at position \a index to \a text.    If the provided text contains an ampersand character ('&'), a    mnemonic is automatically created for it. The character that    follows the '&' will be used as the shortcut key. Any previous    mnemonic will be overwritten, or cleared if no mnemonic is defined    by the text. See the \l {QShortcut#mnemonic}{QShortcut}    documentation for details (to display an actual ampersand, use    '&&').*/void QToolBox::setItemText(int index, const QString &text){    Q_D(QToolBox);    QToolBoxPrivate::Page *c = d->page(index);    if (c)        c->setText(text);}/*!    Sets the icon of the item at position \a index to \a icon.*/void QToolBox::setItemIcon(int index, const QIcon &icon){    Q_D(QToolBox);    QToolBoxPrivate::Page *c = d->page(index);    if (c)        c->setIcon(icon);}#ifndef QT_NO_TOOLTIP/*!    Sets the tooltip of the item at position \a index to \a toolTip.*/void QToolBox::setItemToolTip(int index, const QString &toolTip){    Q_D(QToolBox);    QToolBoxPrivate::Page *c = d->page(index);    if (c)        c->setToolTip(toolTip);}#endif // QT_NO_TOOLTIP/*!    Returns true if the item at position \a index is enabled; otherwise returns false.*/bool QToolBox::isItemEnabled(int index) const{    Q_D(const QToolBox);    const QToolBoxPrivate::Page *c = d->page(index);    return c && c->button->isEnabled();}/*!    Returns the text of the item at position \a index, or an empty string if    \a index is out of range.*/QString QToolBox::itemText(int index) const{    Q_D(const QToolBox);    const QToolBoxPrivate::Page *c = d->page(index);    return (c ? c->text() : QString());}/*!    Returns the icon of the item at position \a index, or a null    icon if \a index is out of range.*/QIcon QToolBox::itemIcon(int index) const{    Q_D(const QToolBox);    const QToolBoxPrivate::Page *c = d->page(index);    return (c ? c->icon() : QIcon());}#ifndef QT_NO_TOOLTIP/*!    Returns the tooltip of the item at position \a index, or an    empty string if \a index is out of range.*/QString QToolBox::itemToolTip(int index) const{    Q_D(const QToolBox);    const QToolBoxPrivate::Page *c = d->page(index);    return (c ? c->toolTip() : QString());}#endif // QT_NO_TOOLTIP/*! \reimp */void QToolBox::showEvent(QShowEvent *e){    QWidget::showEvent(e);}/*! \reimp */void QToolBox::changeEvent(QEvent *ev){    Q_D(QToolBox);    if(ev->type() == QEvent::StyleChange)        d->updateTabs();    QFrame::changeEvent(ev);}/*!  This virtual handler is called after a new item was added or  inserted at position \a index.  \sa itemRemoved() */void QToolBox::itemInserted(int index){    Q_UNUSED(index)}/*!  This virtual handler is called after an item was removed from  position \a index.  \sa itemInserted() */void QToolBox::itemRemoved(int index){    Q_UNUSED(index)}/*!    \fn void QToolBox::setItemLabel(int index, const QString &text)    Use setItemText() instead.*//*!    \fn QString QToolBox::itemLabel(int index) const    Use itemText() instead.*//*!    \fn QWidget *QToolBox::currentItem() const    Use widget(currentIndex()) instead.*//*!    \fn void QToolBox::setCurrentItem(QWidget *widget)    Use setCurrentIndex(indexOf(widget)) instead.*//*!    \fn void QToolBox::setItemIconSet(int index, const QIcon &icon)    Use setItemIcon() instead.*//*!    \fn QIcon QToolBox::itemIconSet(int index) const    Use itemIcon() instead.*//*!    \fn int QToolBox::removeItem(QWidget *widget)    Use toolbox->removeItem(toolbox->indexOf(widget)) instead.*//*!    \fn QWidget *QToolBox::item(int index) const    Use widget() instead.*//*!    \fn void QToolBox::setMargin(int margin)    Sets the width of the margin around the contents of the widget to \a margin.    Use QWidget::setContentsMargins() instead.    \sa margin(), QWidget::setContentsMargins()*//*!    \fn int QToolBox::margin() const    Returns the with of the the margin around the contents of the widget.    Use QWidget::getContentsMargins() instead.    \sa setMargin(), QWidget::getContentsMargins()*//*! \reimp */bool QToolBox::event(QEvent *e){    return QFrame::event(e);}#include "moc_qtoolbox.cpp"#endif //QT_NO_TOOLBOX

⌨️ 快捷键说明

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