Results 1 to 13 of 13

Thread: Change the color of the qwt plot axis, numbers and ticks

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change the color of the qwt plot axis, numbers and ticks

    Quote Originally Posted by bigjoeystud View Post
    I believe you have to override QwtScaleDraw with your own QwtScaleDraw::label routine. The label routine returns a QwtText which can have a color. Here's an example:

    Qt Code:
    1. class ScaleDraw: public QwtScaleDraw
    2. {
    3. public:
    4. ScaleDraw ();
    5. virtual ~ScaleDraw () {};
    6.  
    7. virtual QwtText label (double value) const
    8. {
    9. QwtText ret_val = QwtText (QString::number (value));
    10. ret_val.setColor (_color);
    11. return ret_val;
    12. };
    13.  
    14. private:
    15. QColor _color;
    16. };
    To copy to clipboard, switch view to plain text mode 

    Joey
    Hi again, I think I triyed that solution before with no result.

    Y create a similar code
    Qt Code:
    1. class NewDraw: public QwtScaleDraw
    2. {
    3. public:
    4. NewDraw(QColor c) {my_color = c;};
    5. virtual QwtText label (double value) const
    6. {
    7. QwtText ret_val = QwtText (QString::number (value));
    8. ret_val.setColor (my_color);
    9. return ret_val;
    10. };
    11.  
    12. private:
    13. QColor my_color;
    14. };
    To copy to clipboard, switch view to plain text mode 

    And when I want to chande de color:
    Qt Code:
    1. QColor c = QColorDialog::getColor( Qt::white, this );
    2.  
    3. my_Plot->setAxisScaleDraw(QwtPlot::xBottom, new NewDraw(c));
    To copy to clipboard, switch view to plain text mode 

    But it doesnt work. Instead of changing the color of the numbers, all the numbers and ticks disappear. Any idea? Thanx

  2. #2
    Join Date
    Sep 2007
    Posts
    61
    Thanks
    5
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Change the color of the qwt plot axis, numbers and ticks

    The only time I've seen this is when you are putting things on the stack instead of allocating on the heap. However, if you are doing a new, that's probably right... Your code is virtually identical to mine so I'm at a loss. The only other thing I do differently is also set a font right before setting the color, but I doubt that has anything to do with it. You are only setting the AxisScaleDraw once, right?

    Joey

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

    locke (28th May 2010)

  4. #3
    Join Date
    Feb 2010
    Posts
    64
    Thanks
    18
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Change the color of the qwt plot axis, numbers and ticks

    Yes, only once. I cannot find the solution and there is no much more threads related to this problem

  5. #4
    Join Date
    Mar 2011
    Posts
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Windows

    Default Re: Change the color of the qwt plot axis, numbers and ticks

    I tried the following and it works.

    Qt Code:
    1. QwtScaleWidget *qwtsw = myqwtplot.axisWidget(QwtPlot::xBottom);
    2. QPalette palette = qwtsw->palette();
    3. palette.setColor( QPalette::WindowText, Qt::gray); // for ticks
    4. palette.setColor( QPalette::Text, Qt::gray); // for ticks' labels
    5. qwtsw->setPalette( palette );
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Replies: 1
    Last Post: 16th March 2010, 15:23
  2. Replies: 1
    Last Post: 7th December 2009, 14:59
  3. Axis yLeft cuts of numbers
    By sun in forum Qwt
    Replies: 17
    Last Post: 9th October 2009, 21:36
  4. Replies: 2
    Last Post: 30th June 2009, 17:08
  5. qwp plot axis scale
    By Cal in forum Qwt
    Replies: 1
    Last Post: 11th May 2009, 17:10

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.