Results 1 to 2 of 2

Thread: QwtPlot -> axis -> Draw labels for all kind of ticks ?

  1. #1
    Join Date
    Jul 2009
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default QwtPlot -> axis -> Draw labels for all kind of ticks ?

    Hy there!

    I believe my question is understandable from the title of the post , but I got to be sure:

    I have a QwtPlot with a time axis as the x axis (as in cpluplot example of Qwt) and my wish is to draw labels not only for the major ticks of the axis, instead I want labels (maybe just milliseconds, not the entire time) for all ticks.

    Any help is welcomed. Thanks a lot!

  2. #2
    Join Date
    Jul 2009
    Posts
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QwtPlot -> axis -> Draw labels for all kind of ticks ?

    Heh, I finally found the way to do this.

    QwtScaleDraw also implements this virtual method:

    void draw(QPainter *painter, const QPalette& palette) const;

    So I override it, executed the code that was executing before and added label support also for medium and minor ticks:

    void X::draw(QPainter *painter, const QPalette& palette) const
    {
    QwtScaleDraw::draw(painter, palette);

    if ( hasComponent(QwtAbstractScaleDraw::Labels) )
    {
    painter->save();
    painter->setPen(palette.color(QPalette::Text)); // ignore pen style

    painter->setFont(QFont("Verdana", 7));

    const QList<double> &mediumTicks = scaleDiv().ticks(QwtScaleDiv::MediumTick);

    for (int i = 0; i < (int)mediumTicks.count(); i++)
    {
    const double v = mediumTicks[i];
    if ( scaleDiv().contains(v) )
    drawLabel(painter, mediumTicks[i]);
    }

    painter->setFont(QFont("Verdana", 6));

    const QList<double> &minorTicks = scaleDiv().ticks(QwtScaleDiv::MinorTick);

    for (int i = 0; i < (int)minorTicks.count(); i++)
    {
    const double v = minorTicks[i];
    if ( scaleDiv().contains(v) )
    drawLabel(painter, minorTicks[i]);
    }

    painter->restore();
    }
    }

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

    TEAmerc (25th November 2015)

Similar Threads

  1. Axis with more labels
    By rakkar in forum Qwt
    Replies: 1
    Last Post: 11th October 2009, 10:26
  2. Axis Labels Rendering Quality
    By ChrisW67 in forum Qwt
    Replies: 0
    Last Post: 21st July 2009, 01:49
  3. QwtPlot axis decmials/notation
    By dfirestone in forum Qwt
    Replies: 1
    Last Post: 1st May 2009, 11:42
  4. Histogram axis labels as text
    By DKGear in forum Qwt
    Replies: 1
    Last Post: 30th December 2008, 09:54
  5. Relocating axis labels
    By malcom2073 in forum Qwt
    Replies: 0
    Last Post: 9th May 2008, 14:01

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.