Results 1 to 3 of 3

Thread: select QPixmap area with mouse

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #2
    Join Date
    Feb 2006
    Location
    Romania
    Posts
    2,744
    Thanks
    8
    Thanked 541 Times in 521 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: select QPixmap area with mouse

    You have to subclass QLabel and reimplement mousePressEvent, mouseMoveEvent and paintEvent.

    In mousePressEvent: store the crop coordinates in a QRect or two QPoint's. The local coordinates are stored in the event.
    When you receive the right click(you should implement some kind of click counting - a boolean flag, etc) you have the two local coordinates. Now you can crop the pixmap and set it in the label.

    In mouseMoveEvent: after you have the coordinate for the left mouse click you can update the second coordinate with the current mouse position stored in the event.

    In paintEvent: draw the crop rectangle specified by the left click position and right click position or current mouse position(if you didn't have a right click yet). Note that you first have to call QLabel:aintEvent and then draw your crop rectangle, because you want the label to be able to draw its initial contents.


    As for storing the pixmaps, you can do that with a 1 QPixmap member, for the original image.

  2. The following user says thank you to marcel for this useful post:

    tommy (16th November 2007)

Similar Threads

  1. Weird behaviour of mouse events and QMenu pop-ups
    By Ishark in forum Qt Programming
    Replies: 1
    Last Post: 7th August 2007, 07:46
  2. select a particular area
    By vishesh in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2007, 21:44

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.