Setting the label as a child of the button seems like a good way to do it . The button still works as expected and has its appearance defined by the label.
Qt Code:
  1. #include <QApplication>
  2. #include <QPushButton>
  3. #include <QLabel>
  4.  
  5.  
  6.  
  7. int main(int argc, char *argv[])
  8. {
  9. QApplication a(argc, argv);
  10.  
  11. QPushButton *button = new QPushButton(NULL);
  12. QLabel *label = new QLabel("<h2><i>Hello</i> ""<font color=red>Qt!</font></h2>",button);
  13. QObject::connect(button, SIGNAL(clicked()), &a, SLOT(quit()));
  14. button->show();
  15. button->setWindowTitle("HelloWorld Test Program");
  16.  
  17. label->setAlignment(Qt::AlignCenter|Qt::AlignVCenter);
  18. label->show();
  19.  
  20. return a.exec();
  21. }
To copy to clipboard, switch view to plain text mode