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?
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.