[Qt-interest] Text Clipping in a view

phil prentice philp.cheer at talktalk.net
Wed Mar 25 18:17:09 CET 2009


Hi everybody

  I am using a derived delegate class to output data to a derived QListView 
class.  Each item in the list can be zoomed in and out.  I am using code 
like:-
 painter->drawText(topLeftX, topLeftY + 10, 50 * zoom,
                                        10, Qt::AlignCenter, instName);

  to zoom in & out the items in the view.

  instName is a QString like e.g. "instrumentXYZ"
  The length of the displayed text = 50 * zoom and the width is currently 
always set to 10.

  I am only using zoom factors of 1,2 & 4.  The text is centre aligned.  
However when I zoom out the text(as is expected) is clipped both sides i.e.

  Displayed text zoom factor 4 = "       instrumentXYZ       "
  Displayed text zoom factor 1 = "strumentX"

  With the lower zoom factor I would prefer:- "instrumen"  i.e.  
Qt::AlignLeft;only clip the right side of the text.

  I could probably frig it by using the zoom factor + length of string to 
calculate when to align left rather then centre..  However is there a better 
way to find out if the start of the string is going to be clipped in 
Qt::AlignCenter mode?

Thanks

Phil

  



More information about the Qt-interest-old mailing list