[Interest] QCheckBox not drawing with focus in QStyledItemDelegate

Josh jnfo-d at grauman.com
Mon May 12 19:54:59 CEST 2025


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


More information about the Interest mailing list