Results 1 to 4 of 4

Thread: How do I change the color of arc & text in QwtDial ?

  1. #1
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default How do I change the color of arc & text in QwtDial ?

    I'm trying to create a custom dial (CDial) using QwtDial. The purpose of this is to show the analog meter for some attributes. Now that I've created a dial, I want to change the color of the arc drawn around the scale & also the scale itself. Below is the style code and also the snapshot of it.

    Qt Code:
    1. void CDial::fnSetFeatures()
    2. {
    3. setReadOnly(true);
    4. setFrameShadow(QwtDial::Raised);
    5. setWrapping(false);
    6.  
    7. setStyleSheet("background: white; color: qradialgradient(cx: 0.3, cy: -0.4, fx: 0.3, fy: -0.4, radius: 1.35, stop: 0 #fff, stop: 1 #888);");
    8.  
    9. setTracking(true);
    10. setRange(0, MAG_A_MAX);
    11. setScaleArc(0, 220);
    12. setScale(MAG_A_MAX/10, MAG_A_MAX/10, 100);
    13. setOrigin(150);
    14. setScaleTicks(0, 4, 8);
    15. setMass(0.1);
    16.  
    17. oNeedle = new QwtDialSimpleNeedle(QwtDialSimpleNeedle::Arrow, true, Qt::darkGray,
    18. QColor(Qt::gray).light(130));
    19. oNeedle->setWidth(10);
    20. setNeedle(oNeedle);
    21. }
    To copy to clipboard, switch view to plain text mode 
    CDial.JPG

    Please help me code the arc color and text color. Thank you.
    Last edited by rawfool; 16th July 2012 at 11:15.

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

    Default Re: How do I change the color of arc & text in QwtDial ?

    All colors used in QwtDial are taken from its palette. I'm afraid it is not documented which color role is taken for which element so it might be a good idea to have a look at the implementation ( or play with a custom palette to identify the color roles ).

    For drawing the scale QPalette::Text is used. If you want to have a different colors for tick labels and backbone/ticks ( or for special labels only ) you have to overload QwtDial::scaleLabel() setting a color for the text object.

    HTH,
    Uwe

  3. #3
    Join Date
    Sep 2011
    Location
    Bangalore
    Posts
    248
    Thanks
    91
    Thanked 16 Times in 16 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: How do I change the color of arc & text in QwtDial ?

    Should I overload scaleLabel() or should I override void CDial::draw( QPainter *painter, const QPalette& palette ) const ?

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

    Default Re: How do I change the color of arc & text in QwtDial ?

    No use QWidget::setPalette() or modify the palette using your style sheet.
    By the way: using a stylesheet like in your code snippet above is not necessary - you can do the same using setPalette() in a ( IMHO ) cleaner way.

    Uwe

  5. The following 2 users say thank you to Uwe for this useful post:

    Mesozoic (14th August 2012), rawfool (17th July 2012)

Similar Threads

  1. change text color on QRadioButton
    By vonCZ in forum Newbie
    Replies: 4
    Last Post: 7th November 2012, 21:05
  2. Change text color in QTableWidgetItem
    By npascual in forum Qt Programming
    Replies: 0
    Last Post: 10th May 2011, 18:03
  3. Replies: 3
    Last Post: 22nd January 2010, 17:46
  4. how to change text color in QTableView?
    By phillip_Qt in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2008, 11:03
  5. Change the text color tab page
    By gtthang in forum Qt Programming
    Replies: 4
    Last Post: 18th February 2006, 18:38

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.