You are not logged in.

#1 2009-08-18 04:59:52

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

[SOLVED] How to add Word-Wrapping to a QPushButton

I'm working on a Qt project and I have a QPushButton on which I'd like to allow word wrapping:

wordwrapping_problem.png

I know I can change it to a QLabel, but due to the specific purpose of the application, it needs to be clickable (so I think that means it must be a QPushButton). I've searched around online a bit and the only solution I've been able to find is "inheriting." However, I can't seem to figure out how to do it. Can anyone help? Thanks!

Last edited by tony5429 (2009-08-22 19:20:38)

Offline

#2 2009-08-18 06:03:54

the_isz
Member
Registered: 2009-04-14
Posts: 280

Re: [SOLVED] How to add Word-Wrapping to a QPushButton

I don't think that is possible, as it is against QPushButton's intended design.

However, you could easily derive a class from QLabel and overload the

virtual void QWidget::keyPressEvent ( QKeyEvent * event )

function or install an event filer (http://doc.trolltech.com/4.5/eventsandfilters.html)
on a "plain" QLabel to do the exactly same.

Offline

#3 2009-08-18 16:56:57

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to add Word-Wrapping to a QPushButton

What about this... it is possible to put an image on a QPushButton, correct? Could I use the width of the QPushButton to create an SVG image of the text, with word-wrapping and add the SVG to the QPushButton?

Offline

#4 2009-08-22 19:20:13

tony5429
Member
Registered: 2006-03-28
Posts: 1,017

Re: [SOLVED] How to add Word-Wrapping to a QPushButton

In case anyone is interested, the SVG fix worked. The code is now implemented in vesion 1.1.2 of Yellowcot: http://yellowcot.org

Offline

Board footer

Powered by FluxBB