I am creating a custom QPushButton. If the button has an icon I want the icon centered on the button. If the button has text I want the text centered on the button. I can handle both of those cases. If the button contains both an icon and text I want the icon centered and the text drawn below the button, outside the button rectangle. I am drawing the button image using border-image in a stylesheet.
Inside MyPushButton::paintEvent() I calculate a rectangle and draw the icon using:
style()->drawItemPixmap(&p, iconRect, Qt::AlignLeft | Qt::AlignVCenter,
this->icon().pixmap(iconRect.size()));
I then calculate a text rectangle below the button and do this:
style()->drawItemText(&p, textRect, Qt::AlignCenter, (this->palette()),
true, this->text(), QPalette::ButtonText );
but the text is not visible.
I think this must have something to do with designated "drawable" area, but I can't figure out how to extend that area so that the button image doesn't to fill the area where I want to place the text.
I can do this with a QStyle::drawControl() overload but I'm not sure why. When I trace the code into the CE_PushButtonLabel case the myStyle->rect has already been resized to be large enough to fit the button image and the text.