
Originally Posted by
Lykurg
That behavior you can't realize with css, you have to subclass QPushButton. But that's easy. Just modify the paint event like:
{
QPoint point
= event
->rect
().
center();
point.translate(pixmap.rect().center() * (-1));
}
MyButton::paintEvent(QPaintEvent *event)
{
QPoint point = event->rect().center();
point.translate(pixmap.rect().center() * (-1));
}
To copy to clipboard, switch view to plain text mode
It's perfect ! Exactly what i wanted 
Thanks!
Just a thing : QPoint does not have the method translate(), but i try to use setX and setY which allow to move the image i guess.
Thanks again
PS :This code works fine
void PushButtonPictured
::paintEvent(QPaintEvent *event
) {
QPoint point
= (event
->rect
()).
center();
point.setX(point.x() - pixmap.rect().center().x());
point.setY(point.y() - pixmap.rect().center().y());
painter.drawPixmap(point, pixmap);
}
void PushButtonPictured::paintEvent(QPaintEvent *event)
{
QPushButton::paintEvent(event);
QPixmap pixmap(m_imageFileName);
QPoint point = (event->rect()).center();
point.setX(point.x() - pixmap.rect().center().x());
point.setY(point.y() - pixmap.rect().center().y());
QPainter painter(this);
painter.drawPixmap(point, pixmap);
}
To copy to clipboard, switch view to plain text mode
Bookmarks