QPushButton text disappears when icon is set



  • I designed a form in Qt Designer with a QDialogButtonBox (wondering I should scrap this widget). The QDialogButtonBox has two buttons, QDialogButtonBox::Ok and QDialogButtonBox::Cancel.

    When I add an icon to one of the buttons, its text disappears. How can I have a QPushButton in a QDialogButtonBox with both an icon and text?

    @// after this call, the text disappears
    ui.buttonBox->button(QDialogButtonBox::Ok)
    ->setIcon( QIcon("src/main/resources/buttons/check_ok.bmp") );@



  • Does the button have enough space to show the icon and the text? Maybe the text is just cut off because it isn't resizing properly after the icon is added.

    You could try (and I'm not sure if this would work):

    @
    ui.buttonBox->button(QDialogButtonBox::Ok)->adjustSize()
    @

    Do this after your call to setIcon() and see if anything changes.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.