Results 1 to 5 of 5

Thread: Move the Legend widget using MouseEvent

  1. #1
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Move the Legend widget using MouseEvent

    Hai

    How to move the Legend widget using MouseMove Event ?

    suggestion please





    suree

    Bangalore

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Move the Legend widget using MouseEvent

    Override the mouseMoveEvent(), extract mouse position from event object, and use it to set widgets position.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Mar 2009
    Location
    Tennessee, US
    Posts
    41
    Thanks
    3
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Move the Legend widget using MouseEvent

    Quote Originally Posted by high_flyer View Post
    Override the mouseMoveEvent(), extract mouse position from event object, and use it to set widgets position.
    Make sure to insert your legend class using QwtPlot::insertLegend(your_legend_p, QwtPlot::ExternalLegend) though. This will make the legend a child of the plot instead of placing it somewhere else. Then you can simply captue the mouseMoveEvent() events and then just set your geometry however you would like on your legend widget.

  4. #4
    Join Date
    Jul 2009
    Posts
    49
    Thanks
    9
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Move the Legend widget using MouseEvent

    Thanks for ur reply
    Hai
    In my Project, I have a Main Widget in that QWT Plot Widget and some other widgets [QList ..].
    I can get the MouseMoveEvent of my MainWidget but not able to get QWTPlot MouseMoveEvent.

    suggestion please

    Qt Code:
    1. void MainPlot::mousePressEvent(QMouseEvent *event) // this is my MainWidget called MainPlot
    2. {
    3. ------
    4. ------
    5. }
    To copy to clipboard, switch view to plain text mode 

    and
    my QWTPLOT Mouse Event is
    Qt Code:
    1. void MainPlot::ui->uPlot->mouseMoveEvent(QMouseEvent *) // Uplot is my QWTPLOT widget
    2. {
    3. // some code
    4. ------------------
    5. -------------------
    6.  
    7. }
    To copy to clipboard, switch view to plain text mode 

    suree
    India

  5. #5
    Join Date
    Mar 2009
    Location
    Tennessee, US
    Posts
    41
    Thanks
    3
    Thanked 11 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Move the Legend widget using MouseEvent

    One thing to watch out for is that the plot canvas is a separate widget from the plot itself. The canvas is a child of the plot. More than like you need to watch from the mouse move event in uPlot->canvas().

    Additionally, you have to turn on the mouse tracking for a widget in order to get mouseMoveEvents. You should use:
    Qt Code:
    1. uPlot->setMouseTracking(true);
    2. uPlot->canvas()->setMouseTracking(true);
    To copy to clipboard, switch view to plain text mode 
    Amos
    Qt Programmer Extraordinaire

    Current Work:
    Ripxx Sports Measurement Device - www.ripxx.com
    (Featured in MYTHBUSTERS on 2010-05-19 in S08E08)

Similar Threads

  1. Get QRect of a widget using mouseevent
    By arpspatel in forum Qt Programming
    Replies: 9
    Last Post: 9th March 2010, 04:19
  2. Pass mouseEvent to sibling widget?
    By nish in forum Qt Programming
    Replies: 5
    Last Post: 1st September 2009, 13:00
  3. How to move child widget with parent widget?
    By anupamgee in forum Qt Programming
    Replies: 3
    Last Post: 19th June 2009, 15:23
  4. Remove Legend items, move legends
    By giusepped in forum Qwt
    Replies: 0
    Last Post: 11th February 2009, 02:35
  5. Move child widget along with the parent widget
    By sreedhar in forum Qt Programming
    Replies: 2
    Last Post: 15th May 2006, 12:00

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.