So I've been wrestling with this problem for most of the work day, and at this point I think I need some outside feedback. I've been working with Qt for a couple months now and I'm pretty well versed in C++ so I've got the basics of Qt down and have learned a few of its subtleties, but I can't find an elegant solution to my issue.

I need to have superscript text displayed in the label of a QCheckBox. Now, your initial thought may be to just place and empty check box next to a label which can display rich text. I have seen this suggested many times in various posts about this issue, but I have two problems with this:

  1. Clicking the label does not toggle the check box.
  2. Hovering over the label does not trigger the hoverstate of the check box


The first problem is easy enough to solve. You just need to subclass QLabel and implement mouseClickEvent and emit a clicked signal to connect to the check box's toggle slot. The second problem is somewhat tricky however, and I'm pretty stumped.

My initial instinct was to look for a setState or some such method which would allow me to tell the QCheckBox that it is being hovered over, however no such method exists that I could find. I even tried to use QWidget.setProperty("hover", true but it had no effect. So then I thought that I could place a QCheckBox and a QLabel inside of a custom Widget container which would detect mouseover and if the mouse is over the label I would create a false event containing coordinates of the QCheckBox and pass that to the QCheckBox so it would think it is being hovered over. However you can't explicitly call mouseMoveEvent on a widget. I also tried subclassing QCheckBox and using QTextDocument in the paintEvent to draw rich text next to the checkBox after calling the base class paint event. This worked, but again the checkbox was not counting the drawn text as part of it's contents so hover state was not being triggered.

I feel like I'm close to finding a workable solution here but I just need a push in the right direction. I don't need anyone to write any code for me, but if there's a method I'm missing or something else I could try while subclassing QCheckBox I would be very grateful to have that pointed out.

If all else fails I will just have to stick with a clickable label next to a checkbox, but I would like to avoid that because there are many other checkboxes without the need for rich text in my application and it would be great for them all to have the same behavior.