134void QCheckBox::initStyleOption(QStyleOptionButton *option)
const
138 Q_D(
const QCheckBox);
139 option->initFrom(
this);
141 option->state |= QStyle::State_Sunken;
142 if (d->tristate && d->noChange)
143 option->state |= QStyle::State_NoChange;
145 option->state |= d->checked ? QStyle::State_On : QStyle::State_Off;
146 if (testAttribute(Qt::WA_Hover) && underMouse()) {
147 option->state.setFlag(QStyle::State_MouseOver, d->hovering);
149 option->text = d->text;
150 option->icon = d->icon;
151 option->iconSize = iconSize();
220void QCheckBox::setCheckState(Qt::CheckState state)
223#if QT_CONFIG(accessibility)
224 bool noChange = d->noChange;
226 if (state == Qt::PartiallyChecked) {
232 d->blockRefresh =
true;
233 setChecked(state != Qt::Unchecked);
234 d->blockRefresh =
false;
236 if (state != d->publishedState) {
237 d->publishedState = state;
238 emit checkStateChanged(state);
239#if QT_DEPRECATED_SINCE(6
, 9
)
240 QT_IGNORE_DEPRECATIONS(
241 emit stateChanged(state);
246#if QT_CONFIG(accessibility)
247 if (noChange != d->noChange) {
248 QAccessible::State s;
249 s.checkStateMixed =
true;
250 QAccessibleStateChangeEvent event(
this, s);
251 QAccessible::updateAccessibility(&event);
260QSize QCheckBox::sizeHint()
const
262 Q_D(
const QCheckBox);
263 if (d->sizeHint.isValid())
266 QFontMetrics fm = fontMetrics();
267 QStyleOptionButton opt;
268 initStyleOption(&opt);
269 QSize sz = style()->itemTextRect(fm, QRect(), Qt::TextShowMnemonic,
false,
271 if (!opt.icon.isNull())
272 sz = QSize(sz.width() + opt.iconSize.width() + 4, qMax(sz.height(), opt.iconSize.height()));
273 d->sizeHint = style()->sizeFromContents(QStyle::CT_CheckBox, &opt, sz,
this);
331void QCheckBox::checkStateSet()
335 Qt::CheckState state = checkState();
336 if (state != d->publishedState) {
337 d->publishedState = state;
338 emit checkStateChanged(state);
339#if QT_DEPRECATED_SINCE(6
, 9
)
340 QT_IGNORE_DEPRECATIONS(
341 emit stateChanged(state);
364bool QCheckBox::event(QEvent *e)
367 if (e->type() == QEvent::StyleChange
369 || e->type() == QEvent::MacSizeChange
372 d->setLayoutItemMargins(QStyle::SE_CheckBoxLayoutItem);
373 return QAbstractButton::event(e);