I've had a few issues with word wrapping in my current project. Basically I have a bunch of labels with input widgets in a QGridLayout, and some of the descriptive labels are pretty verbose. So I enabled word wrap so that my labels column wouldn't take up too much space in the layout and force my input widgets to be extra small. There is a known issue which caused my labels to not set the correct height and some of the text would be cut off. For anyone that's interested in that solution, I managed to solve it with this snippet in my label subclass:

Qt Code:
  1. void PLabel::resizeEvent(QResizeEvent *event){
  2. QLabel::resizeEvent( event );
  3. if ( wordWrap() && sizePolicy().verticalPolicy() == QSizePolicy::Minimum ) {
  4. setMinimumHeight(sizeHint().height());
  5. }
  6. }
To copy to clipboard, switch view to plain text mode 

Note: the vertical policy must be minimum.

Now my issue is that the labels are wrapping more than necessary in some cases, and I can't figure out why. For example:

wordwrap_issue.png

You can see here that the first 3 labels are fine, but the last several all take up 2 or more lines when they could easily fit on one. Can anyone clue me in as to what's happening behind the scenes here? Is there some method I can re-implement to control where it wraps?