Results 1 to 6 of 6

Thread: tooltip labelAlignment

  1. #1
    Join Date
    Mar 2009
    Posts
    34
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default tooltip labelAlignment

    Hi,

    i use a QwtPlotMarker to visualize the data value of a qwtplotcurve. when i move the mouse over the datapoint the value will be visualized in the QwtPlotMarker.

    When i move the mouse into the corners the QwtPlotMarker gets displayed out of widget view:
    http://s13.postimg.org/bq6vsrd9j/IMG_6968.jpg

    how can i implement some sort of auto setLabelAlignment?

    Thanks,
    Surf
    Last edited by Surfman19; 30th June 2015 at 21:46.

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

    Default Re: tooltip labelAlignment

    Why using a marker, when implementing a tooltip ?
    Instead you could use QToolTip itself - or maybe easier a customized QwtPlotPicker with a trackerText method, that returns the value of a datapoint or QString::null else.

    Uwe

  3. #3
    Join Date
    Mar 2009
    Posts
    34
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: tooltip labelAlignment

    i mean QwtPlotMarker. the label for QwtPlotMarker should re-adjust automatically in case if i move the mouse over a datapointer beeing at the outer corner...
    do you know what i try to achieve?

    here is the snipped i have at the moment:

    Qt Code:
    1. std::shared_ptr<QwtPlot> plot;
    2. std::shared_ptr<QwtPlotCurve> curve1;
    3. std::shared_ptr<QwtPlotCurve> curve2;
    4. std::shared_ptr<QwtPlotMarker> marker;
    5. std::shared_ptr<QwtPlotShapeItem> plotItem;
    6.  
    7. ///////////////////
    8.  
    9. bool MainWindow::eventFilter(QObject *obj, QEvent *event)
    10. {
    11. if (event->type() == QEvent::MouseMove)
    12. {
    13. QMouseEvent *m = static_cast<QMouseEvent*>(event);
    14.  
    15. QwtPlotItemList curves = plot.get()->itemList(QwtPlotItem::Rtti_PlotCurve);
    16. if (curves.size() == 0) {
    17. return false;
    18. }
    19.  
    20. double dist1 = 1e99;
    21. double dist2 = 1e99;
    22.  
    23. int point_index1 = static_cast<QwtPlotCurve*>(curves[0])->closestPoint(QPoint(m->x(), m->y()), &dist1);
    24. int point_index2 = static_cast<QwtPlotCurve*>(curves[1])->closestPoint(QPoint(m->x(), m->y()), &dist2);
    25.  
    26. if (point_index1 != -1 && point_index2 != -1) {
    27.  
    28. if (dist1 < dist2) {
    29. p = static_cast<QwtPlotCurve*>(curves[0])->sample(point_index1);
    30. }
    31. else {
    32. p = static_cast<QwtPlotCurve*>(curves[1])->sample(point_index2);
    33. }
    34.  
    35. //marker->setSpacing(10);
    36. marker->setLineStyle(QwtPlotMarker::Cross);
    37. marker->setLinePen(QPen(Qt::black, 2, Qt::DotLine));
    38. marker->setLabel("t: " + QString::number(p.x()) + ", Volts: " + QString::number(p.y()));
    39. marker->setLabelAlignment(Qt::AlignRight | Qt::AlignTop); // | Qt::AlignCenter);
    40. //marker->setLabelAlignment(Qt::AlignCenter | Qt::AlignCenter);
    41. marker->setXValue(p.x());
    42. marker->setYValue(p.y());
    43. }
    44. marker->attach(plot.get());
    45. plot->replot();
    46. }
    47.  
    48. return false;
    49. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by Surfman19; 1st July 2015 at 15:42.

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

    Default Re: tooltip labelAlignment

    Quote Originally Posted by Surfman19 View Post
    i mean QwtPlotMarker. the label for QwtPlotMarker should re-adjust automatically in case if i move the mouse over a datapointer beeing at the outer corner...
    do you know what i try to achieve?
    Guess yes, you want to use QwtPlotPicker - even if not knowing it yet :-/

    Uwe

  5. #5
    Join Date
    Mar 2009
    Posts
    34
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: tooltip labelAlignment

    why cant i use QwtPlotMarker?

    do you have a small QwtPlotPicker example? and how do you auto - align the label to avoid the issue i have?

    how can you set the label of the QwtPlotPicker, i look for somth like: void setTrackerText(const QString &str);
    the label should be e.g.: "Amplitude: 1.0, Sample: 10" ... the closest distance to a point of those 2 curves, as in my sample before.

    i see QwtPlotPicker has a move member function: void QwtPlotPicker::move(const QPoint &pos)

    ... how do you know the distance to transform? this will depend on the size of the label, basically the number of characters...
    Last edited by Surfman19; 1st July 2015 at 20:16.

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

    Default Re: tooltip labelAlignment

    Have a look at the curvetracker example - not exactly your use case, but you should get the idea.

    Uwe

Similar Threads

  1. Tooltip
    By ich in forum Qt Programming
    Replies: 1
    Last Post: 19th November 2014, 17:52
  2. Regarding tooltip
    By ashishsaryar in forum Qt Programming
    Replies: 1
    Last Post: 24th December 2011, 08:32
  3. labelAlignment and QPlastiqueStyle
    By aLiEnHeAd in forum Qt Programming
    Replies: 1
    Last Post: 29th March 2011, 16:07
  4. Tooltip in Qwt
    By Ankitha Varsha in forum Qwt
    Replies: 5
    Last Post: 8th December 2009, 12:07
  5. ToolTip....
    By merry in forum Qt Programming
    Replies: 27
    Last Post: 3rd August 2007, 10:42

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.