Page 1 of 2 12 LastLast
Results 1 to 20 of 40

Thread: Widget GPS

  1. #1
    Join Date
    Sep 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Widget GPS

    Hi, I would like to add to my Qt creator Application

    http://casolaredercole.it/mobile/crono2.zip

    the GPS widget like in this image

    http://www.casolaredercole.it/mobile/displaydd.jpg

    Help me please

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Widget GPS

    And what is keeping you from doing that?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Widget GPS

    i don't know how to start/beginner

  4. #4
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    310
    Thanks
    10
    Thanked 31 Times in 25 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Widget GPS

    See "creating custom widgets" starting on page 5 of "C++ GUI programming with Qt4, second edition". I'm sure you can get it somewhere. Or do some google searches on "qt custom widget".

    Creating a custom widget is not so difficult, but is not something we can/will just tell you in this thread.

    One advice : don't start to try to integrate your widget in Qt Designer. That is quite more complex. If it's just for a single application, you can just promote a widget on your form to the new class you create.

    Best regards,
    Marc

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Widget GPS

    Quote Originally Posted by marcvanriet View Post
    See "creating custom widgets" starting on page 5 of "C++ GUI programming with Qt4, second edition". I'm sure you can get it somewhere. Or do some google searches on "qt custom widget".
    I would rather start with the Analog clock widget example.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. #6
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget GPS

    I don't understand exactly what you mean. Do you mean the 5 bar thing in the top-left corner?

    If so, just create a custom widget derived from QWidget, add signals and slots called setValue(int) and value(int) or something like that to set the number of bars shown, and reimplement the paint() method to draw the bars based on the value.

    See the documentation for the QWidget::paintEvent() method and the QPainter class.
    Last edited by MTK358; 15th September 2010 at 02:03.

  7. #7
    Join Date
    Sep 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Widget GPS

    I'm sorry but I have need of the code because I do not know in order to write it... i'm incapable

  8. #8
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget GPS

    You should learn the basics of C++ and Qt (specifically, how to use signals and slots) first, then. Once you know that, it should be quite simple.

  9. #9
    Join Date
    Sep 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Widget GPS

    I have 1 day of time in order to make it help me please

  10. #10
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget GPS

    Quote Originally Posted by toro.86 View Post
    I have 1 day of time in order to make it help me please
    OK. First, do you know how to define your own signals and slots?

    http://doc.trolltech.com/4.6/signalsandslots.html

  11. #11
    Join Date
    Sep 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Widget GPS

    for the time being a any signal goes well or generic slots.

    is it possible to add this widget in this code?

    http://casolaredercole.it/mobile/crono2.zip


    http://www.casolaredercole.it/mobile/displaydd.jpg

  12. #12
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget GPS

    I don't understand.

  13. #13
    Join Date
    Sep 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Widget GPS

    they are interested to graphically visualize 4 vertical lines with under written GPS like in this image
    http://www.casolaredercole.it/mobile/displaydd.jpg ,

    for the time being I do not know the sign that I will receive

  14. #14
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget GPS

    Quote Originally Posted by toro.86 View Post
    for the time being I do not know the sign that I will receive
    What does that mean?

    Anyway, I'm working on an example.

  15. #15
    Join Date
    Sep 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Widget GPS

    Quote Originally Posted by MTK358 View Post
    What does that mean?

    Anyway, I'm working on an example.
    one moment max 5 minute I sent you one private message

  16. #16
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget GPS

    I didn't get any private message. Anyway, the code:

    barwidget.h

    Qt Code:
    1. #ifndef BARWIDGET_H
    2. #define BARWIDGET_H
    3.  
    4. #include <QtGui>
    5.  
    6. class BarWidget : public QWidget
    7. {
    8. Q_OBJECT
    9. public:
    10. explicit BarWidget(QWidget *parent = 0);
    11.  
    12. int value();
    13.  
    14. protected:
    15. void paintEvent(QPaintEvent *);
    16.  
    17. signals:
    18. void valueChanged(int);
    19.  
    20. public slots:
    21. void setValue(int);
    22.  
    23. private:
    24. int currentValue;
    25. };
    26.  
    27. #endif // BARWIDGET_H
    To copy to clipboard, switch view to plain text mode 

    barwidget.cpp:

    Qt Code:
    1. #include "barwidget.h"
    2.  
    3. BarWidget::BarWidget(QWidget *parent) :
    4. QWidget(parent)
    5. {
    6. currentValue = 0;
    7. }
    8.  
    9. int BarWidget::value()
    10. {
    11. return currentValue;
    12. }
    13.  
    14. void BarWidget::setValue(int newValue)
    15. {
    16. if (newValue > 5)
    17. newValue = 5;
    18. else if (newValue < 0)
    19. newValue = 0;
    20. currentValue = newValue;
    21. emit valueChanged(newValue);
    22. repaint();
    23. }
    24.  
    25. void BarWidget::paintEvent(QPaintEvent *)
    26. {
    27. QPainter p(this);
    28. p.setPen(Qt::NoPen)
    29. p.setBrush(palette().text()); // draw the bars using the current theme's text color
    30.  
    31. float barWidth = 0.15; // change this to the preferred width of the bars, as a fraction of the widget's width. Do not make it more than 0.20, or one fifth
    32. float gapWidth = (1.0 - (barWidth * 5)) / 4;
    33.  
    34. switch (currentValue) // since there is no break after each case, it will fall through and draw the smaller bars
    35. {
    36. case 5:
    37. p.drawRect(QRectF( (barWidth+gapWidth)*4*width(), height()*(0/5.0), barWidth*width(), height() ));
    38. case 4:
    39. p.drawRect(QRectF( (barWidth+gapWidth)*3*width(), height()*(1/5.0), barWidth*width(), height() ));
    40. case 3:
    41. p.drawRect(QRectF( (barWidth+gapWidth)*2*width(), height()*(2/5.0), barWidth*width(), height() ));
    42. case 2:
    43. p.drawRect(QRectF( (barWidth+gapWidth)*1*width(), height()*(3/5.0), barWidth*width(), height() ));
    44. case 1:
    45. p.drawRect(QRectF( (barWidth+gapWidth)*0*width(), height()*(4/5.0), barWidth*width(), height() ));
    46. }
    47.  
    48. p.end();
    49. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by MTK358; 15th September 2010 at 14:59.

  17. #17
    Join Date
    Sep 2010
    Posts
    19
    Qt products
    Qt4
    Platforms
    MacOS X

    Default Re: Widget GPS

    thanks i sent you a private message now

  18. #18
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget GPS

    I got your PM, and I didn't realize you want the whole thing! I thought you only wanted the bar part that said "GPS" under it!

  19. #19
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Widget GPS

    I wouldn't do that for $100

    On the other hand I'll give you (the original poster) a hint - prepare a set of graphics files for each subcomponent of your "widget" and only render them to the final canvas. That's what is often done in embedded world and I think that's what you are targetting too.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  20. #20
    Join Date
    Jun 2010
    Posts
    142
    Thanks
    11
    Thanked 4 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Widget GPS

    Another question: do you want one widget with all the things or will it be OK to use separate existing widgets, like QLabel and QLCDNumber (which makes much more sense)?

    BTW what is this for, if you don't mind sharing?

Similar Threads

  1. Replies: 10
    Last Post: 29th May 2010, 18:42
  2. Replies: 7
    Last Post: 14th January 2010, 08:47
  3. Replies: 4
    Last Post: 3rd March 2008, 22:15
  4. Replies: 3
    Last Post: 17th October 2007, 12:52
  5. Replies: 1
    Last Post: 5th November 2006, 23:50

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.