Results 1 to 3 of 3

Thread: adding lettering within a qwtdial (i.e. "rpm x1000")

  1. #1
    Join Date
    Oct 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default adding lettering within a qwtdial (i.e. "rpm x1000")

    I'm mostly new at this but I'm attempting to build a virtual car dashboard. My main problem has arisen in trying to put text within a dial. I'm using the qwt designer plugins but I need to further style the dials from the code. Copying from the qwtdials speedometer example I attempted to add "rpm x1000" with this code:

    Qt Code:
    1. #include <QtGui>
    2. #include <qpainter.h>
    3. #include <qwt_dial_needle.h>
    4. #include "dashcar.h"
    5. #include "ui_dashcar.h"
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. ui->Main_Dial_Rpm->drawScaleContents(QPainter *painter,
    2. const QPoint &center, int radius) const
    3. {
    4. QRect rect(0, 0, 2 * radius, 2 * radius - 10);
    5. rect.moveCenter(center);
    6.  
    7. const QColor color = palette().color(QPalette::Text);
    8. painter->setPen(color);
    9.  
    10. const int flags = Qt::AlignBottom | Qt::AlignHCenter;
    11. painter->drawText(rect, flags, "rpm x1000");
    12. }
    To copy to clipboard, switch view to plain text mode 

    however I get the following errors:

    Qt Code:
    1. dashcar.cpp: In constructor ‘DashCar::DashCar(QWidget*)’:
    2. dashcar.cpp:33: error: expected primary-expression before ‘*’ token
    3. dashcar.cpp:33: error: ‘painter’ was not declared in this scope
    4. dashcar.cpp:34: error: expected primary-expression before ‘const’
    5. dashcar.cpp:34: error: expected primary-expression before ‘int’
    6. dashcar.cpp:34: error: expected ‘;’ before ‘const’
    7. make: *** [dashcar.o] Error 1
    To copy to clipboard, switch view to plain text mode 

    Also, if possible I would like to know how to turn the dial face different colors to serve as a shift light, and I guess from what I read it involves a similar process.

    Any ideas?
    Last edited by xicer; 26th October 2010 at 20:38.

  2. #2
    Join Date
    Oct 2010
    Posts
    2
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11

    Default Re: adding lettering within a qwtdial (i.e. "rpm x1000")

    Basically, is it possible to draw stuff onto a qwtdial that was added via designer or do I have to make a custom class.

  3. #3
    Join Date
    Aug 2012
    Location
    Tucson, AZ, USA
    Posts
    7
    Thanks
    7
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: adding lettering within a qwtdial (i.e. "rpm x1000")

    I ended up building a custom class, but I still use the designer to format and place the dial inside a frame. During initialization, I close the dial, delete it, and replace it with my custom implementation. Likely not the best method, but it certainly works.
    Do it once, do it right.

Similar Threads

  1. Replies: 0
    Last Post: 20th September 2010, 09:58
  2. Replies: 1
    Last Post: 15th January 2010, 15:14
  3. Replies: 3
    Last Post: 8th July 2008, 19:37
  4. Translation QFileDialog standart buttons ("Open"/"Save"/"Cancel")
    By victor.yacovlev in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2008, 19:05
  5. QFile Problem~ "Unknow error" in "open(QIODevice::ReadWrite)"
    By fengtian.we in forum Qt Programming
    Replies: 3
    Last Post: 23rd May 2007, 15:58

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.