Results 1 to 2 of 2

Thread: On click event for a QPixmap

  1. #1
    Join Date
    Jan 2008
    Posts
    27
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default On click event for a QPixmap

    Hi,

    I am drawing a Pixmap in my paintEvent of my widget (shown below), I want to be able to basically be able to click the image and enlarge it and then click it again and shrink it back to normal size. The transforming stuff I got down, just trying to figure out how to create a click event for the QPixmap.

    Any ideas?

    Thanks.
    Qt Code:
    1. void paintEvent(QPaintEvent *event) {
    2. QPainter painter(this);
    3.  
    4. // attempt of the new image and scale it graciously
    5. painter.setRenderHint(QPainter::Antialiasing);
    6. painter.setRenderHint(QPainter::SmoothPixmapTransform);
    7.  
    8. QPointF center(pixmap.width()/2.0, pixmap.height()/2.0);
    9.  
    10. painter.translate(center);
    11. painter.scale(m_scale, m_scale);
    12. painter.translate(-center);
    13.  
    14. if (m_scale == 1.0)
    15. painter.drawPixmap(5,22,pixmap.scaled(75,75, Qt::KeepAspectRatio));
    16. else
    17. painter.drawPixmap(QPointF(5, 22), pixmap);
    18.  
    19. QWidget::paintEvent(event);
    20. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: On click event for a QPixmap

    QWidget has specialized mouse event handlers; QWidget::mousePressEvent(), QWidget::mouseReleaseEvent() etc. Reimplement necessary mouse event handlers just like you have reimplemented QWidget::paintEvent().
    J-P Nurmi

  3. The following user says thank you to jpn for this useful post:

    codeslicer (22nd February 2008)

Similar Threads

  1. Double Click Capturing
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2011, 15:12
  2. Replies: 1
    Last Post: 16th October 2007, 23:41
  3. The event fired by the mouse click on the frame
    By Placido Currò in forum Qt Programming
    Replies: 8
    Last Post: 3rd March 2007, 10:05
  4. QGraphicsScene Click / Double Click
    By philentropist in forum Qt Programming
    Replies: 1
    Last Post: 9th February 2007, 05:32
  5. mouse click event
    By vijay anandh in forum Qt Programming
    Replies: 1
    Last Post: 1st May 2006, 10:24

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.