
Originally Posted by
ber0y
i only set the steel sheet here, in the constructor. My code works fine to display a image under a text, not the contrary (the text under the image) and that's my problem
Ok, know I understand you right! Sorry, took some time...
That behavior you can't realize with css, you have to subclass QPushButton. But that's easy. Just modify the paint event like:
{
QPushButton::paintEvent(event
);
// let Qt draw the regular button // and now just paint your image on the button (and text)
QPoint point
= event
->rect
().
center();
point.translate(pixmap.rect().center() * (-1));
p.drawPixmap(point, pixmap);
}
MyButton::paintEvent(QPaintEvent *event)
{
QPushButton::paintEvent(event); // let Qt draw the regular button
// and now just paint your image on the button (and text)
QPixmap pixmap(":myPixmap.png");
QPoint point = event->rect().center();
point.translate(pixmap.rect().center() * (-1));
QPainter p(this);
p.drawPixmap(point, pixmap);
}
To copy to clipboard, switch view to plain text mode
not tested but should work...
Bookmarks