Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can try inherit from QCheckBox and draw what you want. Look to this example custom push_button (add shadow to the text on the button). <code></p> <pre><code>#include "CustomButton.h" #include &lt;QStylePainter&gt; #include &lt;QStyleOptionButton&gt; #include &lt;QMenu&gt; CustomButton::CustomButton(QWidget *parent): QPushButton(parent) { } void CustomButton::paintEvent(QPaintEvent *event) { QStylePainter p(this); QFontMetrics font = this-&gt;fontMetrics(); QRect textRect = font.boundingRect(text()); int x = rect().center().x()-textRect.center().x(); int y = rect().center().y()-textRect.center().y(); ++y; p.drawControl(QStyle::CE_PushButton, getStyleOption()); //draw button with stylesheet QStyleOptionButton opt = getStyleOption(); opt.text = text(); QPen tempPen = p.pen(); p.setPen(Qt::white); p.drawText(x, y, text()); //draw text shadow on the button p.setPen(tempPen); p.drawControl(QStyle::CE_PushButtonLabel, opt); //draw text with stylesheet //QPushButton::paintEvent(event); } QStyleOptionButton CustomButton::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() &amp;&amp; menu()-&gt;isVisible())) opt.state |= QStyle::State_Sunken; if (isChecked()) opt.state |= QStyle::State_On; if (!isFlat() &amp;&amp; !isDown()) opt.state |= QStyle::State_Raised; //opt.text = text(); opt.icon = icon(); opt.iconSize = iconSize(); return opt; } </code></pre> <p></code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload