views:

287

answers:

3

Hi, I'm trying to have a multi-line checkbox/radio with Qt using standard QCheckbox/QRadio.

I didn't find the direct solution since QRadio{wrap:true;} has no effect. The only thing possible would be to access to the QRadio->label->setLineWrap(true) but

  1. I'd like to do that from the designer
  2. not having to rewrite a widget

Any idea beside putting a QRadio and a QLabel next to each others?

Thx, Boris.

A: 

The only way I know (but it's not "layoutable") is putting \n sign into a string.

Kamil Klimek
+1  A: 

That indeed is really annoying and cannot be solved without reimplementation: the label uses Qt::PlainText if I'm not mistaken. In our projects, the UI team solved this with two approaches.

Using the QRadioButton button as a title

Layout using the QRadioButton as a title

Rewrite the QRadioButton text in such a fashion that it has only a brief description of the option. Put a QLabel underneath it and add a longer description. We use a smaller font and a little indentation to make it look neat. This is used frequently in Mac OS X, for example.

Removing the text from the radio button

Layout using buddy labels

Relayout the UI so that each radio button is put on the left of a QLabel. Add the whole text to the QLabel and set the label as the radio buttons' buddy. This is the least functional approach, because clicking the label does not check the radio button. Also, alignment is not very good.

andref
Thanks for your answer. I solved my issue with the 2nd solution you explained. This is not very good in the layout but works... I really hope Qt will solve this issue in a close future! Thanks again anyway.
Boris Gougeon
+1  A: 

I succeeded adding a layout and a label as a child for the radio button, and changing the vertical size policy to Preferred (instead of Fixed).

Unfortunately this didn't automatically make it react to the mouse hovers and clicks like the native label, but watch a hack: I setStyleSheet("border:none") for the radio button and it started working. Maybe that's some feature happening behind the scenes; I'd love to have some certainty.

And the indicator can be aligned using "QRadioButton::indicator{subcontrol-position:top left}" <- http://doc.trolltech.com/qq/qq20-qss.html

ulzha