How to make a flat button with rich text formating with Qt4?

I would like to create flat buttons displaying rich text and images. For instance a button should be able to display:

|¯¯¯¯¯¯| Title of Button ¯¯¯¯| | ICON | Description of button | |_____̣̣_|___________________|

I've been playing around with Qt4 and I couldn't find an easy way to produce such a button. Adding a QLabel as a child of a QPushButton does not work properly (the text is not aligned properly and the button does not respect the size of the label's content).

Is there a way to produce a simple flat button that can handle rich text and images as its content? Can I create a button from a QLabel perhaps?

Answers


If you look at the documentation, you can see that QPushButton doesn't accept child widgets.

So you will have to write your own widget. QLabel is a good start. Give it the same border and color that a QButton would get (the documentation of the flat property of the QPushButton should help).

And you'll need to implement mousePressEvent plus add the necessary button slots. A good idea is probably to look into the source code of QAbstractButton to see how it's implemented.


Need Your Help

Linking twitter to facebook page

facebook twitter

I just created a page on FB as of August 1st 2012, and I am constantly getting this error as I am trying to link my twitter account to the facebook page.

Silverlight Threading and its usage

silverlight silverlight-3.0 multithreading

Scenario : I am working on LOB application, as in silverlight every call to service is Async so automatically UI is not blocked when the request is processed at server side.