Results 1 to 7 of 7

Thread: QSS problem on a QPushButton

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jul 2009
    Posts
    12
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows Android

    Thumbs up Re: QSS problem on a QPushButton

    Quote Originally Posted by Lykurg View Post
    That behavior you can't realize with css, you have to subclass QPushButton. But that's easy. Just modify the paint event like:
    Qt Code:
    1. MyButton::paintEvent(QPaintEvent *event)
    2. {
    3. QPoint point = event->rect().center();
    4. point.translate(pixmap.rect().center() * (-1));
    5. }
    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

    Qt Code:
    1. void PushButtonPictured::paintEvent(QPaintEvent *event)
    2. {
    3. QPushButton::paintEvent(event);
    4.  
    5. QPixmap pixmap(m_imageFileName);
    6. QPoint point = (event->rect()).center();
    7. point.setX(point.x() - pixmap.rect().center().x());
    8. point.setY(point.y() - pixmap.rect().center().y());
    9.  
    10. QPainter painter(this);
    11. painter.drawPixmap(point, pixmap);
    12. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by ber0y; 21st July 2009 at 08:24. Reason: find solution

Similar Threads

  1. problem with paint and erase in frame
    By M.A.M in forum Qt Programming
    Replies: 9
    Last Post: 4th May 2008, 20:17
  2. Problem with enabling QPushButton!
    By Krish in forum Newbie
    Replies: 6
    Last Post: 5th March 2008, 14:49
  3. PyQt QTimer problem { FIXED }
    By WinchellChung in forum Newbie
    Replies: 0
    Last Post: 1st March 2008, 16:50
  4. problem with opengl, zooming, drawpixels, and origin
    By ntp in forum General Programming
    Replies: 0
    Last Post: 22nd February 2008, 21:48
  5. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.