[Interest] QCheckBox not drawing with focus in QStyledItemDelegate

Axel Spoerl axel.spoerl at qt.io
Tue May 13 08:46:42 CEST 2025


Hi Josh,

thanks for you mail and problem description.
A bit hard to guess, since two issues seem to occur at the same time.

You seem to expect that the first checkbox is automatically focused, but it isn't.
The missing focus frame can be a consequence or a separate (styling) issue.
You can enforce a specific focus chain by calling QWidget::setTabOrder() (tab order and focus chain are the same thing).
Depending on whether the dialog subclass has buttons (e.g. Save / Discard), one of them may be its focus proxy.
That may also interfere with your focus chain expectations.

You may want to raise a topic in https://forum.qt.io
Describing the expected behavior and adding a small reproducer will help to identify and solve the issue.

Cheers
Axel

________________________________
From: Interest <interest-bounces at qt-project.org> on behalf of Josh <jnfo-d at grauman.com>
Sent: Monday, 12 May 2025 19:54
To: interest at qt-project.org <interest at qt-project.org>
Subject: [Interest] QCheckBox not drawing with focus in QStyledItemDelegate

Hello,

I'm sure this is something simple, but I just can't figure it out. I have
created a QStyledItemDelegate subclass. It creates an editor that is a
QDialog subclass that has QCheckBoxes in it. The problem is that when the
QDialog subclass is shown, the first checkbox isn't drawn with the (blue)
focus rectangle around it. If you press an arrow key, the next checkbox
will be drawn with it. I call setFocus(Qt::TabFocusReason) on the first
checkbox, and then call update() on it, but it won't draw with the focus
rectangle. It has the keyboard focus, when I press 'space' it checks the
box. But if I press 'tab' the underlying QTableWidget changes cells,
unless I first press an arrow key, then the correct checkbox will be drawn
with the focus and then the tab key will switch between the checkboxes. I
clearly am not understanding something about the focus.

Sorry for the complicated email, but in short, what should I do to have
the qcheckbox be drawn with the focus rectangle when my qdialog editor is
first shown?

Josh
_______________________________________________
Interest mailing list
Interest at qt-project.org
https://lists.qt-project.org/listinfo/interest
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20250513/84698bcd/attachment.htm>


More information about the Interest mailing list