Results 1 to 7 of 7

Thread: QwPlottMultiBarChart determining legend title of bar segment under cursor

Threaded View

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

    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

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

    Buffy (23rd September 2014)

Similar Threads

  1. Segment fault
    By kenchan in forum Qt Programming
    Replies: 14
    Last Post: 25th December 2012, 11:30
  2. Replies: 0
    Last Post: 29th October 2012, 11:23
  3. Replies: 2
    Last Post: 26th October 2012, 16:26
  4. I need a 16 segment LCD display control????
    By phoenixcomm in forum Newbie
    Replies: 2
    Last Post: 2nd July 2012, 00:26
  5. Replies: 2
    Last Post: 2nd October 2009, 15: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
  •  
Qt is a trademark of The Qt Company.