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

📄 qpushbutton.cpp

📁 qt-x11-opensource-src-4.1.4.tar.gz源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
    update();    updateGeometry();}bool QPushButton::autoDefault() const{    Q_D(const QPushButton);    if(d->autoDefault == QPushButtonPrivate::Auto)        return ( d->dialogParent() != 0 );    return d->autoDefault;}void QPushButton::setDefault(bool enable){    Q_D(QPushButton);    if (d->defaultButton == enable)        return;    d->defaultButton = enable;    if (d->defaultButton) {        if (QDialog *dlg = d->dialogParent())            dlg->d_func()->setMainDefault(this);    }    update();#ifndef QT_NO_ACCESSIBILITY    QAccessible::updateAccessibility(this, 0, QAccessible::StateChanged);#endif}bool QPushButton::isDefault() const{    Q_D(const QPushButton);    return d->defaultButton;}/*!    \reimp*/QSize QPushButton::sizeHint() const{    Q_D(const QPushButton);    ensurePolished();    int w = 0, h = 0;    QStyleOptionButton opt = d->getStyleOption();    // calculate contents size...#ifndef QT_NO_ICON    if (!icon().isNull()) {        int ih = opt.iconSize.height();        int iw = opt.iconSize.width() + 4;        w += iw;        h = qMax(h, ih);    }#endif#ifndef QT_NO_MENU    if (menu())        w += style()->pixelMetric(QStyle::PM_MenuButtonIndicator, &opt, this);#endif    QString s(text());    bool empty = s.isEmpty();    if (empty)        s = QString::fromLatin1("XXXX");    QFontMetrics fm = fontMetrics();    QSize sz = fm.size(Qt::TextShowMnemonic, s);    if(!empty || !w)        w += sz.width();    if(!empty || !h)        h = qMax(h, sz.height());    return (style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), this).            expandedTo(QApplication::globalStrut()));}/*!\reimp*/void QPushButton::paintEvent(QPaintEvent *){    Q_D(QPushButton);    QStylePainter p(this);    p.drawControl(QStyle::CE_PushButton, d->getStyleOption());}/*! \reimp */void QPushButton::keyPressEvent(QKeyEvent *e){    Q_D(QPushButton);    switch (e->key()) {    case Qt::Key_Enter:    case Qt::Key_Return:        if (autoDefault() || d->defaultButton) {            click();            break;        }        // fall through    default:        QAbstractButton::keyPressEvent(e);    }}/*!    \reimp*/void QPushButton::focusInEvent(QFocusEvent *e){    Q_D(QPushButton);    if (e->reason() != Qt::PopupFocusReason && autoDefault() && !d->defaultButton) {        d->defaultButton = true;        QDialog *dlg = qobject_cast<QDialog*>(window());        if (dlg)            dlg->d_func()->setDefault(this);    }    QAbstractButton::focusInEvent(e);}/*!    \reimp*/void QPushButton::focusOutEvent(QFocusEvent *e){    Q_D(QPushButton);    if (e->reason() != Qt::PopupFocusReason && autoDefault() && d->defaultButton) {        QDialog *dlg = qobject_cast<QDialog*>(window());        if (dlg)            dlg->d_func()->setDefault(0);        else            d->defaultButton = false;    }    QAbstractButton::focusOutEvent(e);#ifndef QT_NO_MENU    if (d->menu && d->menu->isVisible())        // restore pressed status        setDown(true);#endif}#ifndef QT_NO_MENU/*!    Associates the popup menu \a menu with this push button. This    turns the button into a menu button, which in some styles will    produce a small triangle to the right of the button's text.    Ownership of the menu is \e not transferred to the push button.    \sa menu()*/void QPushButton::setMenu(QMenu* menu){    Q_D(QPushButton);    if (menu && !d->menu) {        disconnect(this, SIGNAL(pressed()), this, SLOT(_q_popupPressed()));        connect(this, SIGNAL(pressed()), this, SLOT(_q_popupPressed()));    }    d->menu = menu;    update();    updateGeometry();}/*!    Returns the button's associated popup menu or 0 if no popup menu    has been set.    \sa setMenu()*/QMenu* QPushButton::menu() const{    Q_D(const QPushButton);    return d->menu;}/*!    Shows (pops up) the associated popup menu. If there is no such    menu, this function does nothing. This function does not return    until the popup menu has been closed by the user.*/void QPushButton::showMenu(){    Q_D(QPushButton);    if (!d || !d->menu)        return;    setDown(true);    d->_q_popupPressed();}void QPushButtonPrivate::_q_popupPressed(){    Q_Q(QPushButton);    if (!down || !menu)        return;    menu->setNoReplayFor(q);    bool horizontal = true;#if !defined(QT_NO_TOOLBAR)    QToolBar *tb = qobject_cast<QToolBar*>(q->parentWidget());    if (tb && tb->orientation() == Qt::Vertical)        horizontal = false;#endif    QRect rect = q->rect();    QSize menuSize = menu->sizeHint();    QPoint globalPos = q->mapToGlobal(rect.topLeft());    int x = globalPos.x();    int y = globalPos.y();    if (horizontal) {        if (globalPos.y() + rect.height() + menuSize.height() <= qApp->desktop()->height()) {            y += rect.height();        } else {            y -= menuSize.height();        }        if (q->layoutDirection() == Qt::RightToLeft)            x += rect.width() - menuSize.width();    } else {        if (globalPos.x() + rect.width() + menu->sizeHint().width() <= qApp->desktop()->width())            x += rect.width();        else            x -= menuSize.width();    }    QPointer<QPushButton> guard(q);    //Because of a delay in menu effects, we must keep track of the    //menu visibility to avoid flicker on button release    menuOpen = true;    menu->exec(QPoint(x, y));    if (guard) {        menuOpen = false;        q->setDown(false);    }}#endif // QT_NO_MENUvoid QPushButton::setFlat(bool flat){    Q_D(QPushButton);    if (d->flat == flat)        return;    d->flat = flat;    update();    updateGeometry();}bool QPushButton::isFlat() const{    Q_D(const QPushButton);    return d->flat;}/*! \reimp */bool QPushButton::event(QEvent *e){    return QAbstractButton::event(e);}#ifdef QT3_SUPPORT/*!    Use one of the constructors that doesn't take the \a name    argument and then use setObjectName() instead.*/QPushButton::QPushButton(QWidget *parent, const char *name)    : QAbstractButton(*new QPushButtonPrivate, parent){    Q_D(QPushButton);    setObjectName(QString::fromAscii(name));    d->init();}/*!    Use one of the constructors that doesn't take the \a name    argument and then use setObjectName() instead.*/QPushButton::QPushButton(const QString &text, QWidget *parent, const char *name)    : QAbstractButton(*new QPushButtonPrivate, parent){    Q_D(QPushButton);    setObjectName(QString::fromAscii(name));    d->init();    setText(text);}/*!    Use one of the constructors that doesn't take the \a name    argument and then use setObjectName() instead.*/QPushButton::QPushButton(const QIcon& icon, const QString &text, QWidget *parent, const char *name)    : QAbstractButton(*new QPushButtonPrivate, parent){    Q_D(QPushButton);    setObjectName(QString::fromAscii(name));    d->init();    setText(text);    setIcon(icon);}#endif/*!    \fn void QPushButton::openPopup()    Use showMenu() instead.*//*!    \fn bool QPushButton::isMenuButton() const    Use menu() != 0 instead.*//*!    \fn void QPushButton::setPopup(QMenu* popup)    Use setMenu() instead.*//*!    \fn QMenu* QPushButton::popup() const    Use menu() instead.*/#include "moc_qpushbutton.cpp"

⌨️ 快捷键说明

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