41 state = QAbstractButtonPrivate::styleButtonState(state);
42 if (tristate && noChange)
43 state |= QStyle::State_NoChange;
45 state |= (checked ? QStyle::State_On : QStyle::State_Off);
46 if (q->testAttribute(Qt::WA_Hover) && q->underMouse())
47 state.setFlag(QStyle::State_MouseOver, hovering);
226void QCheckBox::setCheckState(Qt::CheckState state)
229#if QT_CONFIG(accessibility)
230 bool noChange = d->noChange;
232 if (state == Qt::PartiallyChecked) {
238 d->blockRefresh =
true;
239 setChecked(state != Qt::Unchecked);
240 d->blockRefresh =
false;
242 if (state != d->publishedState) {
243 d->publishedState = state;
244 emit checkStateChanged(state);
245#if QT_DEPRECATED_SINCE(6
, 9
)
246 QT_IGNORE_DEPRECATIONS(
247 emit stateChanged(state);
252#if QT_CONFIG(accessibility)
253 if (noChange != d->noChange) {
254 QAccessible::State s;
255 s.checkStateMixed =
true;
256 QAccessibleStateChangeEvent event(
this, s);
257 QAccessible::updateAccessibility(&event);
266QSize QCheckBox::sizeHint()
const
268 Q_D(
const QCheckBox);
269 if (d->sizeHint.isValid())
272 QFontMetrics fm = fontMetrics();
273 QStyleOptionButton opt;
274 initStyleOption(&opt);
275 QSize sz = style()->itemTextRect(fm, QRect(), Qt::TextShowMnemonic,
false,
277 if (!opt.icon.isNull())
278 sz = QSize(sz.width() + opt.iconSize.width() + 4, qMax(sz.height(), opt.iconSize.height()));
279 d->sizeHint = style()->sizeFromContents(QStyle::CT_CheckBox, &opt, sz,
this);
337void QCheckBox::checkStateSet()
341 Qt::CheckState state = checkState();
342 if (state != d->publishedState) {
343 d->publishedState = state;
344 emit checkStateChanged(state);
345#if QT_DEPRECATED_SINCE(6
, 9
)
346 QT_IGNORE_DEPRECATIONS(
347 emit stateChanged(state);
370bool QCheckBox::event(QEvent *e)
373 if (e->type() == QEvent::StyleChange
375 || e->type() == QEvent::MacSizeChange
378 d->setLayoutItemMargins(QStyle::SE_CheckBoxLayoutItem);
379 return QAbstractButton::event(e);