Results 1 to 7 of 7

Thread: QwPlottMultiBarChart determining legend title of bar segment under cursor

  1. #1
    Join Date
    Mar 2012
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default QwPlottMultiBarChart determining legend title of bar segment under cursor

    Some of my users QwtPlotMultiBarCharts are very complicated and it's not always easy to determine the legend title for each small section of each bar. They would like to be able to hover over a bar section and have the program show the legend title as a tool tip. If the performance is too slow, I can change the implementation to having the user click first and then display the text.

    I'm overloading QwtPlotPicker::trackerTextF() trying to display the legend title of the bar section that is under the cursor.

    I've successfully overloaded the trackerTextF() so that my method is being called rather than the QwtPlotPicker version.
    I've successfully accessed the QwtPlotMultiBarChart::legendData & I see all my legend titles.

    My problem is determining what section of the bar is under the cursor. I thought at first I could loop through the series data and find what is under the cursor based on the x and y coordinates but this doesn't work since sometimes the multi bars are stacked and sometimes they are grouped. Is there a way to ask qwt what is under the cursor? What am I missing?

    Any help in accomplishing this task would be greatly appreciated.

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwPlottMultiBarChart determining legend title of bar segment under cursor

    I've successfully accessed the QwtPlotMultiBarChart::legendData & I see all my legend titles.
    So far you did what I would recommend - beside that you could also use QwtPlotMultiBarChart::barTitles() directly.

    My problem is determining what section of the bar is under the cursor. I thought at first I could loop through the series data and find what is under the cursor based on the x and y coordinates but this doesn't work since sometimes the multi bars are stacked and sometimes they are grouped.
    As you already found a way to identify the chart below the mouse you can easily identify if its current state is Grouped or Stacked. Not sure why this is a problem - beside, that you need different implementations for both modes ?

    But maybe it is a better idea to introduce a lookup table with the geometries of each bar:

    Qt Code:
    1. class YourChart: public QwtPlotMultiBarChart
    2. {
    3. virtual void draw( QPainter *painter,
    4. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    5. const QRectF &canvasRect ) const
    6. {
    7. m_barGeometries.clear();
    8. QwtPlotMultiBarChart::draw( painter, xMap, yMap, canvasRect );
    9. }
    10.  
    11. virtual void drawBar( QPainter *painter,
    12. int sampleIndex, int valueIndex, const QwtColumnRect &rect ) const
    13. {
    14. m_barGeometries.store( sampleIndex, valueIndex, rect );
    15. QwtPlotMultiBarChart::drawBar( painter, sampleIndex, valueIndex, rect );
    16. }
    17.  
    18. QwtText barTitleAt( QPoint &pos ) const
    19. {
    20. // find sampleIndex/valueIndex from m_barGeometries
    21. // and return the title using barTitles()
    22. ...
    23. }
    24. private:
    25. LookUpTable m_barGeometries;
    26. };
    To copy to clipboard, switch view to plain text mode 

    As you need widget coordinates fro barTitleAt() you would have to overload QwtPlotPicker::trackerText() instead of QwtPlotPicker::trackerTextF().

    Uwe

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

    Buffy (23rd September 2014)

  4. #3
    Join Date
    Mar 2012
    Posts
    8
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: QwPlottMultiBarChart determining legend title of bar segment under cursor

    Uwe,
    Thanks so much for the quick response. Now it's making more sense and I like the idea of the lookup table and saving this information during creation. This will remove my problems with the current state and will also help me when things are zoomed and/or panned in. I'll give it a try.
    Buffy

  5. #4
    Join Date
    Jul 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: QwPlottMultiBarChart determining legend title of bar segment under cursor

    I have a similar need but to display the y value of the bar when hovering. I am trying to use the hint from Uwe, but am a little lost. How does the m_barGeometries know if a QPointF is in a given bar? The LookUpTable class has the sampleIndex, valueIndex and QwtColumnRect. I thought I could get the QRect from QwtColumnRect and check if the rect contains point. However, rect seems to have only a relative size and not tied to the plot. All my stored QRect objects all have the same size 9x13 with xp and yp equal zero.

    I am new to Qwt and any help on how to determine if mouse location is over a specific bar would be greatly appreciated.

    Thanks

    Tim

  6. #5
    Join Date
    Jul 2015
    Posts
    2
    Qt products
    Qt5
    Platforms
    MacOS X Windows

    Default Re: QwPlottMultiBarChart determining legend title of bar segment under cursor

    I found a few problems with my solution. First of all, if sampleIndex was -1 then I should not store it in the look up table. I guess that draw call is for the legend. Second, the coordinate system that the QwtColumnRect contains is the same as the output of trackerPosition(). So I don't need to inverse transform it. I can use it directly in the QRectF object returned by QwtColumnRect. I just call QRectF::contains(pos) and it works.

    Regards

    Tim

  7. #6
    Join Date
    Oct 2015
    Posts
    1
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: QwPlottMultiBarChart determining legend title of bar segment under cursor

    Quote Originally Posted by Uwe View Post

    Qt Code:
    1. class YourChart: public QwtPlotMultiBarChart
    2. {
    3. virtual void draw( QPainter *painter,
    4. const QwtScaleMap &xMap, const QwtScaleMap &yMap,
    5. const QRectF &canvasRect ) const
    6. {
    7. m_barGeometries.clear();
    8. QwtPlotMultiBarChart::draw( painter, xMap, yMap, canvasRect );
    9. }
    10. };
    To copy to clipboard, switch view to plain text mode 

    Uwe
    Hi Uwe!
    Uh, I might be missing something. But how can I clear the lookup table if the method is const?
    btw, thank you for your responses at qt forums, which I have been coming back to every once and again for the past weeks.

  8. #7
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,309
    Thanked 879 Times in 827 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QwPlottMultiBarChart determining legend title of bar segment under cursor

    Well this more a C++ question: check the "mutable" keyword.

    Uwe

Similar Threads

  1. Segment fault
    By kenchan in forum Qt Programming
    Replies: 14
    Last Post: 25th December 2012, 12:30
  2. Replies: 0
    Last Post: 29th October 2012, 12:23
  3. Replies: 2
    Last Post: 26th October 2012, 17:26
  4. I need a 16 segment LCD display control????
    By phoenixcomm in forum Newbie
    Replies: 2
    Last Post: 2nd July 2012, 01:26
  5. Replies: 2
    Last Post: 2nd October 2009, 16:32

Tags for this Thread

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.