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
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
i don't know how to start/beginner
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
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 03:03.
I'm sorry but I have need of the code because I do not know in order to write it... i'm incapable
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.
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
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
I don't understand.
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
I didn't get any private message. Anyway, the code:
barwidget.h
Qt Code:
#ifndef BARWIDGET_H #define BARWIDGET_H #include <QtGui> { Q_OBJECT public: int value(); protected: signals: void valueChanged(int); public slots: void setValue(int); private: int currentValue; }; #endif // BARWIDGET_HTo copy to clipboard, switch view to plain text mode
barwidget.cpp:
Qt Code:
#include "barwidget.h" { currentValue = 0; } int BarWidget::value() { return currentValue; } void BarWidget::setValue(int newValue) { if (newValue > 5) newValue = 5; else if (newValue < 0) newValue = 0; currentValue = newValue; emit valueChanged(newValue); repaint(); } { p.setPen(Qt::NoPen) p.setBrush(palette().text()); // draw the bars using the current theme's text color 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 float gapWidth = (1.0 - (barWidth * 5)) / 4; switch (currentValue) // since there is no break after each case, it will fall through and draw the smaller bars { case 5: case 4: case 3: case 2: case 1: } p.end(); }To copy to clipboard, switch view to plain text mode
Last edited by MTK358; 15th September 2010 at 15:59.
thanks i sent you a private message now
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!
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.
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?
Bookmarks