I have a QPushButton and on that I have a text and and icon. I want to make the text on the button to be bold and red. Looked at other forums, googled and lost my hope. Seems there is no way to do that if the button has an icon (of course if you don't create a new icon which is text+former icon). Is that the only way? Anyone has a better idea?
C++ – Qt – QPushButton text formatting
buttoncformattingqt
Related Topic
- C++ – std::string formatting like sprintf
- C++ – How to convert a std::string to int
- C++ – Image Processing: Algorithm Improvement for ‘Coca-Cola Can’ Recognition
- C++ – Are the days of passing const std::string & as a parameter over
- C++ – the difference between ‘typedef’ and ‘using’ in C++11
- C# – System.Windows.Application.GetResourceStream returns null
Best Answer
You really don't need to subclass to change the formatting of your button, rather use stylesheets e.g.
Applying this to the button that you want to change will make the buttons text 18pt, bold and red. You can apply via
widget->setStyleSheet()
Applying this to a widget in the hierarchy above will style all the buttons underneath, the QT stylesheet mechanism is very flexible and fairly well documented.
You can set stylesheets in the designer too, this will style the widget that you are editing immediately