Results 1 to 5 of 5

Thread: setting needle size in qwtCompass

  1. #1
    Join Date
    May 2007
    Location
    Australia
    Posts
    30
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question setting needle size in qwtCompass

    Hello,
    This is my first post so I hope I give all the required info.
    I use Qt 4.2.3 and Qwt 5.0.1

    I'm trying to create a compass or a dial that will show wind direction.
    I created a class that inherits QwtCompass and in it's constructor:

    windNeedle = new QwtCompassWindArrow( Style1, red, black );
    rose = new QwtSimpleCompassRose( 4, 1 );

    I instanciate this class in a layout which is inside a QWidget. So the compass is only part of what is displayed on the screen.

    I have 2 problems:

    1. I would like to change the size and direction of the windNeedle. The function I found is drawStyle1Needle(...) or draw() which calls that function.
    When I try to use that function in the constructor I get the error: QPainter::begin: Widget painting can only begin as a result of a paintEvent.
    What is the right way to use those functions? How do I create the paintEvent and how and when do I use the draw() function?

    2. I would also like to change the direction of the windNeedle (since it represents wind direction and it may change) - How do I get the value after the user moved the needle and how do I set the needle to a certain direction? - I guess the setting part would require redrawing of the compass which is my first problem.

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

    Default Re: setting needle size in qwtCompass

    How do I get the value after the user moved the needle...
    You have to look at the derived API of the base classes of QwtCompass:

    1) QwtDoubleRange::value(), or
    2) QwtAbstractSlider::valueChanged(double) signal.

    0.0 means north, 270.0 is west.

    Guess you want write something like this: "connect(compass, SIGNAL(valueChanged(double)), ...);"

    ... and how do I set the needle to a certain direction.
    "QwtAbstractSlider::setValue(double)", you don't have to repaint anything.

    I would like to change the size of the windNeedle
    Qt Code:
    1. class YourCompass::public QwtCompass
    2. {
    3. ...
    4.  
    5. virtual void YourCompass::drawNeedle(
    6. QPainter *painter, const QPoint &pos,
    7. int radius, double direction,
    8. QPalette::ColorGroup colorGroup) const
    9. {
    10. radius = ...; // decrease the radius here
    11. QwtCompass::drawNeedle(painter, pos, radius,
    12. direction, colorGroup);
    13. }
    14. }
    To copy to clipboard, switch view to plain text mode 

    HTH,
    Uwe

  3. #3
    Join Date
    May 2007
    Location
    Australia
    Posts
    30
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Post Re: setting needle size in qwtCompass

    Thank you Uwe.

    I can set and get the Needle value now, but I still have a problem with the needle size.

    Can you please tell me what I'm missing?

    I have a class that has an instance of the QwtCompass:
    Qt Code:
    1. class Atmosphere: public QWidget
    2. {
    3. Atmosphere::Atmosphere
    4. {
    5. a=new myCompass();
    6. connect(myCompass, SIGNAL(valueChanged(double)), ...);
    7. }
    8. ...
    9. }
    10.  
    11. class myCompass::public QwtCompass
    12. {
    13. ...
    14. myCompass::myCompass( parent ) : QwtCompass(parent)
    15. {
    16. windNeedle = new QwtCompassWindArrow( Style1, red, black );
    17. rose = new QwtSimpleCompassRose( 4, 1 );
    18. update();
    19. }
    20.  
    21. // As in your replay, I've added:
    22. virtual void YourCompass::drawNeedle( QPainter *painter, const QPoint &pos,
    23. int radius, double direction,
    24. QPalette::ColorGroup colorGroup) const
    25. ...
    26. }
    27.  
    28. }
    To copy to clipboard, switch view to plain text mode 


    I've added a printout in my drawNeedle function. It looks as if the function is never executed (not even when I move the needle or resize the window) . Do I need to call it manually?
    Last edited by jacek; 20th July 2007 at 15:56. Reason: missing [code] tags

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

    Default Re: setting needle size in qwtCompass

    Of course it has to look like this.

    Qt Code:
    1. class myCompass: public QwtCompass
    2. {
    3. ...
    4.  
    5. virtual void drawNeedle( QPainter *painter, const QPoint &pos,
    6. int radius, double direction,
    7. QPalette::ColorGroup colorGroup) const
    8. {
    9. ...
    10. }
    11. };
    To copy to clipboard, switch view to plain text mode 

    If this doesn't help start the debugger, set a breakpoint in QwtDial::drawNeedle and check if it is called from myCompass::drawNeedle.

    Uwe

  5. #5
    Join Date
    May 2007
    Location
    Australia
    Posts
    30
    Thanks
    6
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: setting needle size in qwtCompass

    Thank you Uwe.

    It works now. I didn't type it properly: const QPoint instead of const QPoint &

Similar Threads

  1. Replies: 3
    Last Post: 30th January 2007, 08:35
  2. Qt 4.1.1 linker warnings
    By Matt Smith in forum Installation and Deployment
    Replies: 0
    Last Post: 26th February 2006, 23:14

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.