本文整理汇总了C++中QStyleOptionButton类的典型用法代码示例。如果您正苦于以下问题:C++ QStyleOptionButton类的具体用法?C++ QStyleOptionButton怎么用?C++ QStyleOptionButton使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QStyleOptionButton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Q_UNUSED
/*!
Reimplementation of QCheckBox::paintEvent.\n
Draws a custom checkbox suitable for fixed modifier.
*/
void FixedCheckBox::paintEvent(QPaintEvent *event)
{
Q_UNUSED(event);
QStylePainter p(this);
QStyleOptionButton opt;
opt.initFrom(this);
if (mDefaultValue) {
p.setBrush(QColor(225, 225, 225));
} else {
p.setBrush(Qt::white);
}
p.drawRect(opt.rect.adjusted(0, 0, -1, -1));
// if is checked then draw a tick
if (mTickState) {
p.setRenderHint(QPainter::Antialiasing);
QPen pen = p.pen();
pen.setWidthF(1.5);
p.setPen(pen);
QVector<QPoint> lines;
lines << QPoint(opt.rect.left() + 3, opt.rect.center().y());
lines << QPoint(opt.rect.center().x() - 1, opt.rect.bottom() - 3);
lines << QPoint(opt.rect.center().x() - 1, opt.rect.bottom() - 3);
lines << QPoint(opt.rect.width() - 3, opt.rect.top() + 3);
p.drawLines(lines);
}
}
示例2: isEnabled
/**
* Draws the button label.
*/
void ColorButton::paintEvent (QPaintEvent * e)
{
// first paint the complete button
QPushButton::paintEvent(e);
// repaint the rectangle area
QPalette::ColorGroup group = isEnabled() ? hasFocus() ? QPalette::Active : QPalette::Inactive : QPalette::Disabled;
QColor pen = palette().color(group,QPalette::ButtonText);
{
QPainter paint(this);
paint.setPen(pen);
if (d->drawFrame) {
paint.setBrush(QBrush(d->col));
paint.drawRect(5, 5, width()-10, height()-10);
}
else {
paint.fillRect(5, 5, width()-10, height()-10, QBrush(d->col));
}
}
// overpaint the rectangle to paint icon and text
QStyleOptionButton opt;
opt.init(this);
opt.text = text();
opt.icon = icon();
opt.iconSize = iconSize();
QStylePainter p(this);
p.drawControl(QStyle::CE_PushButtonLabel, opt);
}
示例3: buttonSizeHint
//-----------------------------------------------------------------------------
QSize ctkCollapsibleButton::buttonSizeHint()const
{
int w = 0, h = 0;
QStyleOptionButton opt;
opt.initFrom(this);
// indicator
QSize indicatorSize = QSize(style()->pixelMetric(QStyle::PM_IndicatorWidth, &opt, this),
style()->pixelMetric(QStyle::PM_IndicatorHeight, &opt, this));
int indicatorSpacing = style()->pixelMetric(QStyle::PM_CheckBoxLabelSpacing, &opt, this);
int ih = indicatorSize.height();
int iw = indicatorSize.width() + indicatorSpacing;
w += iw;
h = qMax(h, ih);
// text
QString string(this->text());
bool empty = string.isEmpty();
if (empty)
{
string = QString::fromLatin1("XXXX");
}
QFontMetrics fm = this->fontMetrics();
QSize sz = fm.size(Qt::TextShowMnemonic, string);
if(!empty || !w)
{
w += sz.width();
}
h = qMax(h, sz.height());
//opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height
QSize buttonSize = (style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), this).
expandedTo(QApplication::globalStrut()));
return buttonSize;
}
示例4: isDefault
QStyleOptionButton TCircleButton::styleOption() const
{
QStyleOptionButton opt;
opt.init(this);
if (isEnabled())
opt.state |= QStyle::State_Enabled;
if (hasFocus())
opt.state |= QStyle::State_HasFocus;
if (isDown())
opt.state |= QStyle::State_Sunken;
if (! isFlat() && ! isDown())
opt.state |= QStyle::State_Raised;
opt.features = isDefault() ? QStyleOptionButton::DefaultButton : QStyleOptionButton::None;
opt.text = text();
opt.icon = icon();
opt.iconSize = QSize(m_diameter,m_diameter);
QRect r = rect();
opt.rect = QRect(r.x(),r.y(), m_diameter, m_diameter);
return opt;
}
示例5: drawButton
void ColorButton::drawButton(QPainter *p)
{
QStyleOptionButton buttonOptions;
buttonOptions.init(this);
buttonOptions.features = QStyleOptionButton::None;
buttonOptions.rect = rect();
buttonOptions.palette = palette();
buttonOptions.state = (isDown() ? QStyle::State_Sunken : QStyle::State_Raised);
if (!mIsFlat)
{
style()->drawPrimitive(QStyle::PE_PanelButtonBevel, &buttonOptions, p, this);
}
else
{
style()->drawPrimitive(QStyle::PE_FrameDefaultButton, &buttonOptions, p, this);
}
p->save();
drawButtonLabel(p);
p->restore();
QStyleOptionFocusRect frectOptions;
frectOptions.init(this);
frectOptions.rect = style()->subElementRect(QStyle::SE_PushButtonFocusRect, &buttonOptions, this);
if (hasFocus())
{
style()->drawPrimitive(QStyle::PE_FrameFocusRect, &frectOptions, p, this);
}
}
示例6: painter
void StatusLineEdit::paintEvent(QPaintEvent *event)
{
if(hasFocus()) {
QLineEdit::paintEvent(event);
} else {
QStylePainter painter(this);
if(underMouse()) {
QStyleOptionButton opt;
opt.initFrom(this);
opt.state &= ~QStyle::State_HasFocus;
painter.drawControl(QStyle::CE_PushButton, opt);
}
painter.setPen(palette().color(QPalette::Text));
QRect textRect = rect();
textRect.moveLeft(4);
textRect.moveTop(1);
if(text().isEmpty()) {
painter.setPen(palette().color(QPalette::Dark));
QFont font = painter.font();
font.setItalic(true);
painter.setFont(font);
painter.drawText(textRect, Qt::AlignVCenter | Qt::TextSingleLine, tr("Description..."));
} else {
painter.drawText(textRect, Qt::AlignVCenter | Qt::TextSingleLine, painter.fontMetrics().elidedText(text(), Qt::ElideRight, width() - 4));
}
}
}
示例7: getStyleOption
QStyleOptionButton OrientationButton::getStyleOption() const
{
QStyleOptionButton opt;
opt.initFrom(this);
if (orientation_ == Qt::Vertical)
{
QSize size = opt.rect.size();
size.transpose();
opt.rect.setSize(size);
}
opt.features = QStyleOptionButton::None;
if (isFlat())
opt.features |= QStyleOptionButton::Flat;
if (menu())
opt.features |= QStyleOptionButton::HasMenu;
if (autoDefault() || isDefault())
opt.features |= QStyleOptionButton::AutoDefaultButton;
if (isDefault())
opt.features |= QStyleOptionButton::DefaultButton;
if (isDown() || (menu() && menu()->isVisible()))
opt.state |= QStyle::State_Sunken;
if (isChecked())
opt.state |= QStyle::State_On;
if (!isFlat() && !isDown())
opt.state |= QStyle::State_Raised;
opt.text = text();
opt.icon = icon();
opt.iconSize = iconSize();
return opt;
}
示例8: paintEvent
void LocationButton::paintEvent ( QPaintEvent * )
{
QStyleOptionButton option;
option.initFrom( this );
option.state |= QStyle::State_Enabled;
QPainter p( this );
if( underMouse() )
{
p.save();
p.setRenderHint( QPainter::Antialiasing, true );
QColor c = palette().color( QPalette::Highlight );
p.setPen( c );
p.setBrush( c.lighter( 150 ) );
p.setOpacity( 0.2 );
p.drawRoundedRect( option.rect.adjusted( 0, 2, 0, -2 ), 5, 5 );
p.restore();
}
QRect r = option.rect.adjusted( PADDING, 0, -PADDING - (b_arrow ? 10 : 0), 0 );
QString str( text() );
/* This check is absurd, but either it is not done properly inside elidedText(),
or boundingRect() is wrong */
if( r.width() < fontMetrics().boundingRect( text() ).width() )
str = fontMetrics().elidedText( text(), Qt::ElideRight, r.width() );
p.drawText( r, Qt::AlignVCenter | Qt::AlignLeft, str );
if( b_arrow )
{
option.rect.setWidth( 10 );
option.rect.moveRight( rect().right() );
style()->drawPrimitive( QStyle::PE_IndicatorArrowRight, &option, &p );
}
}
示例9: calculateTextSpace
QSize caToggleButton::calculateTextSpace()
{
QStyleOptionButton option;
option.initFrom(this);
d_savedTextSpace = style()->subElementRect(QStyle::SE_CheckBoxContents, &option, this).size();
return d_savedTextSpace;
}
示例10: widget
QRect LinkDescriptionTaskMenuInlineEditor::editRectangle() const
{
QWidget *w = widget(); // TODO: What is the exact description area?
QStyleOptionButton opt;
opt.init(w);
return w->style()->subElementRect(QStyle::SE_PushButtonContents, &opt, w);
}
示例11: Q_Q
//-----------------------------------------------------------------------------
QSize ctkPushButtonPrivate::buttonSizeHint()const
{
Q_Q(const ctkPushButton);
int w = 0, h = 0;
QStyleOptionButton opt;
opt.initFrom(q);
// icon
QSize iconSize = q->iconSize();
int ih = iconSize.height();
int iw = iconSize.width() + this->IconSpacing;
w += iw;
h = qMax(h, ih);
// text
QString string(q->text());
bool empty = string.isEmpty();
if (empty)
{
string = QString::fromLatin1("XXXX");
}
QFontMetrics fm = q->fontMetrics();
QSize sz = fm.size(Qt::TextShowMnemonic, string);
if(!empty || !w)
{
w += sz.width();
}
h = qMax(h, sz.height());
//opt.rect.setSize(QSize(w, h)); // PM_MenuButtonIndicator depends on the height
QSize buttonSize = (q->style()->sizeFromContents(QStyle::CT_PushButton, &opt, QSize(w, h), q).
expandedTo(QApplication::globalStrut()));
return buttonSize;
}
示例12: paintButton
bool RenderThemeQt::paintButton(RenderObject* o, const RenderObject::PaintInfo& i, const IntRect& r)
{
QStyle* style = 0;
QPainter* painter = 0;
QWidget* widget = 0;
if (!getStylePainterAndWidgetFromPaintInfo(i, style, painter, widget))
return true;
QStyleOptionButton option;
option.initFrom(widget);
option.rect = r;
// Get the correct theme data for a button
EAppearance appearance = applyTheme(option, o);
if(appearance == PushButtonAppearance || appearance == ButtonAppearance)
style->drawControl(QStyle::CE_PushButton, &option, painter);
else if(appearance == RadioAppearance)
style->drawControl(QStyle::CE_RadioButton, &option, painter);
else if(appearance == CheckboxAppearance)
style->drawControl(QStyle::CE_CheckBox, &option, painter);
return false;
}
示例13: paintEvent
void QColorButton::paintEvent (QPaintEvent *p)
{
QPushButton::paintEvent (p);
QStyleOptionButton option;
option.initFrom (this);
int x, y, w, h;
QRect r = style()->subElementRect (QStyle::SE_PushButtonContents, &option, this);
r.getRect (&x, &y, &w, &h);
int margin = style()->pixelMetric (QStyle::PM_ButtonMargin, &option, this);
x += margin;
y += margin;
w -= 2*margin;
h -= 2*margin;
if (isChecked() || isDown()) {
x += style()->pixelMetric (QStyle::PM_ButtonShiftHorizontal, &option, this );
y += style()->pixelMetric (QStyle::PM_ButtonShiftVertical, &option, this );
}
QPainter painter (this);
QColor fillCol = isEnabled() ? col : palette().brush(QPalette::Window).color();
qDrawShadePanel (&painter, x, y, w, h, palette(), true, 1, NULL);
if (fillCol.isValid())
painter.fillRect (x+1, y+1, w-2, h-2, fillCol);
if (hasFocus()) {
style()->subElementRect (QStyle::SE_PushButtonFocusRect, &option, this);
style()->drawPrimitive (QStyle::PE_FrameFocusRect, &option, &painter, this);
}
}
示例14: getStyleOption
QStyleOptionButton QxtPushButtonPrivate::getStyleOption() const
{
QStyleOptionButton option;
option.initFrom(&qxt_p());
if (rot & Vertical_Mask)
{
QSize size = option.rect.size();
size.transpose();
option.rect.setSize(size);
}
option.features = QStyleOptionButton::None;
if (qxt_p().isFlat())
option.features |= QStyleOptionButton::Flat;
if (qxt_p().menu())
option.features |= QStyleOptionButton::HasMenu;
if (qxt_p().autoDefault() || qxt_p().isDefault())
option.features |= QStyleOptionButton::AutoDefaultButton;
if (qxt_p().isDefault())
option.features |= QStyleOptionButton::DefaultButton;
if (qxt_p().isDown() || (qxt_p().menu() && qxt_p().menu()->isVisible()))
option.state |= QStyle::State_Sunken;
if (qxt_p().isChecked())
option.state |= QStyle::State_On;
if (!qxt_p().isFlat() && !qxt_p().isDown())
option.state |= QStyle::State_Raised;
if (!isRichText())
{
option.text = qxt_p().text();
option.icon = qxt_p().icon();
option.iconSize = qxt_p().iconSize();
}
return option;
}
示例15: getStyleOption
QStyleOptionButton RichTextPushButton::getStyleOption() const
{
QStyleOptionButton opt;
opt.initFrom(this);
opt.features = QStyleOptionButton::None;
if (isFlat())
opt.features |= QStyleOptionButton::Flat;
if (menu())
opt.features |= QStyleOptionButton::HasMenu;
if (autoDefault() || isDefault())
opt.features |= QStyleOptionButton::AutoDefaultButton;
if (isDefault())
opt.features |= QStyleOptionButton::DefaultButton;
if (isDown() || (menu() && menu()->isVisible()))
opt.state |= QStyle::State_Sunken;
if (isChecked())
opt.state |= QStyle::State_On;
if (!isFlat() && !isDown())
opt.state |= QStyle::State_Raised;
if (!isRichText)
opt.text = QPushButton::text();
opt.icon = icon();
opt.iconSize = iconSize();
return opt;
}