Results 1 to 2 of 2

Thread: Getting sender for mouseclick with QwtPlot

  1. #1
    Join Date
    Jan 2011
    Posts
    32
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Getting sender for mouseclick with QwtPlot

    Hello all,

    I have run across a difficulty that I can't seem to find a direct answer to. My application has a QwtPlot instantiated. What I want to do is set things up so that when a user right-clicks anywhere on the QwtPlot window, I will receive a mouse event, and I can determine which of QwtPlot's QwtPlotItems it was that was clicked.

    If the user right clicks on the lower x axis label, for instance, I would like a mouse event and then be able to determine that it was the label that was clicked on. Getting the mouse event is no problem. I have found several ways to do that. The sender, though, seems to be a little more difficult. I can retrieve a QWidget * using childAt, but then I have not been able to find a way to determine what kind of object it was that dispatched the signal. Was it the QLabel on the bottom x axis, the axis markers on the left y axis, etc. When I debug and look at the information that I receive (i.e. what information is visible in the debugger regarding the particular object), the objectName is always blank, so that doesn't help me. It also appears that all of the messages come from either the QwtPlot itself or the QwtPlotCanvas, depending on which method I use.

    I've tried subclassing my QwtPlot and overriding the mousePressEvent, but thus far I seem to be unable to determine who exactly was clicked on.

    Anyone have any ideas to steer me in the right direction?

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,230
    Thanks
    302
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Getting sender for mouseclick with QwtPlot

    You should be asking this question in the Qwt subforum, not here in the main Qt forum.

    To answer the question, you seem to be misunderstanding how Qwt is implemented. The labels on the axes, for example, are not QLabel widgets. They are QwtText (which is similar to a QString) which has been painted onto the QwtScaleWidget that represents the axis. Clicking on the QwtText does nothing, because it isn't a QWidget and doesn't emit signals.

    Likewise, QwtPlotItem instances are not QWidgets, so they do not emit signals either.

    If you click somewhere on the plot, the childAt() method is probably retrieving either the QwtPlotCanvas (the area where the plot items are displayed) or one of the QwtScaleWidget instances if you clicked on an axis. And that's it. Aside from QwtPlot itself, those are the only actual QWidget instances. Everything else is just stuff that is painted onto the canvas or scales.

    If you want to implement a system that identifies what plot item has been clicked by the user, you're going to have to do it yourself. I'd suggest you first look at QwtPlotPicker, which will tell you (in data coordinates) where the click occurred on the canvas. Then, you will have to keep a list of all of your plot items and traverse it to see if the click occurred within one of their bounding rects (for example), or if you are plotting symbols as part of a curve, you'll have to iterate over the curve points and see if the pixel coordinates of the click fall within the pixel-based rect of a symbol. If you need to convert between data coordinates and pixels, you'll use the QwtScaleMaps for the appropriate axes.

    This is based on my knowledge of Qwt 5.x. Uwe has a release candidate for a new 6.0 version, but I do not know if it provides any more support for plot item selection than 5.x.

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

    lxman (23rd January 2011)

Similar Threads

  1. Simulating mouseclick on a HbAction from qtestlib
    By LearningCurve in forum Qt Programming
    Replies: 1
    Last Post: 4th December 2009, 01:16
  2. how to get MouseClick Event in this case
    By yxmaomao in forum Qt Programming
    Replies: 3
    Last Post: 17th July 2008, 03:03
  3. showing menu mouseclick event with opengl object
    By validator in forum Qt Programming
    Replies: 1
    Last Post: 8th March 2008, 23:25
  4. select QGraphicsItems by mouseclick
    By Shawn in forum Qt Programming
    Replies: 20
    Last Post: 31st July 2007, 13:23
  5. [QTable] Disable centering of rows on mouseclick
    By BrainB0ne in forum Qt Programming
    Replies: 4
    Last Post: 30th October 2006, 12:47

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.