30 QStyleOptionButton opt;
31 bool down, tristate, noChange, checked, hovering;
38 opt.state |= QStyle::State_Sunken;
39 if (tristate && noChange)
40 opt.state |= QStyle::State_NoChange;
42 opt.state |= checked ? QStyle::State_On : QStyle::State_Off;
43 if (q->testAttribute(Qt::WA_Hover) && q->underMouse()) {
45 opt.state |= QStyle::State_MouseOver;
47 opt.state &= ~QStyle::State_MouseOver;
51 opt.iconSize = q->size();
58 Qt::LayoutDirection direction;
61 QFontMetrics fontMetrics = widget->fontMetrics();
64 state = QStyle::State_None;
65 if (widget->isEnabled())
66 state |= QStyle::State_Enabled;
67 if (widget->hasFocus())
68 state |= QStyle::State_HasFocus;
69 if (widget->window()->testAttribute(Qt::WA_KeyboardFocusChange))
70 state |= QStyle::State_KeyboardFocusChange;
71 if (widget->underMouse())
72 state |= QStyle::State_MouseOver;
73 if (widget->window()->isActiveWindow())
74 state |= QStyle::State_Active;
76 direction = widget->layoutDirection();
77 rect = widget->rect();
78 palette = widget->palette();
79 fontMetrics = widget->fontMetrics();
87 QStyleOptionButton opt;
88 initStyleOption(&opt);
89 p.drawControl(QStyle::CE_CheckBox, opt);
98 QStyleOptionButton *btn;
103 QStyleOptionButton subopt = *btn;
104 subopt.rect = subElementRect(QStyle::SE_CheckBoxIndicator, btn, widget);
105 drawPrimitive(QStyle::PE_IndicatorCheckBox, &subopt, p, widget);
106 subopt.rect = subElementRect(QStyle::SE_CheckBoxContents, btn, widget);
107 drawControl(QStyle::CE_CheckBoxLabel, &subopt, p, widget);
108 if (btn->state & State_HasFocus) {
109 QStyleOptionFocusRect fropt;
110 fropt.QStyleOption::operator=(*btn);
111 fropt.rect = subElementRect(QStyle::SE_CheckBoxFocusRect, btn, widget);
112 drawPrimitive(QStyle::PE_FrameFocusRect, &fropt, p, widget);
118 QStyleOptionButton *opt;
123 const QStyleOptionButton *btn = qstyleoption_cast<
const QStyleOptionButton *>(opt);
124 uint alignment = visualAlignment(btn->direction, Qt::AlignLeft | Qt::AlignVCenter);
125 if (!styleHint(SH_UnderlineShortcut, btn, widget))
126 alignment |= Qt::TextHideMnemonic;
128 QRect textRect = btn->rect;
129 if (!btn->icon.isNull()) {
130 const auto dpr = p->device()->devicePixelRatio();
131 pix = btn->icon.pixmap(btn->iconSize, dpr,
132 btn->state & State_Enabled ? QIcon::Normal : QIcon::Disabled);
133 drawItemPixmap(p, btn->rect, alignment, pix);
134 if (btn->direction == Qt::RightToLeft)
135 textRect.setRight(textRect.right() - btn->iconSize.width() - 4);
137 textRect.setLeft(textRect.left() + btn->iconSize.width() + 4);
139 if (!btn->text.isEmpty()){
140 drawItemText(p, textRect, alignment | Qt::TextShowMnemonic,
141 btn->palette, btn->state & State_Enabled, btn->text, QPalette::WindowText);