PDA

View Full Version : Widget GPS



toro.86
14th September 2010, 17:06
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

wysota
14th September 2010, 17:40
And what is keeping you from doing that?

toro.86
14th September 2010, 23:28
i don't know how to start/beginner

marcvanriet
14th September 2010, 23:38
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

wysota
15th September 2010, 00:40
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.

MTK358
15th September 2010, 01:59
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.

toro.86
15th September 2010, 13:18
I'm sorry but I have need of the code because I do not know in order to write it... i'm incapable

MTK358
15th September 2010, 13:47
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.

toro.86
15th September 2010, 13:52
I have 1 day of time in order to make it help me please

MTK358
15th September 2010, 14:09
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

toro.86
15th September 2010, 14:15
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

MTK358
15th September 2010, 14:16
I don't understand.

toro.86
15th September 2010, 14:23
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

MTK358
15th September 2010, 14:41
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.

toro.86
15th September 2010, 14:48
What does that mean?

Anyway, I'm working on an example.

one moment max 5 minute I sent you one private message

MTK358
15th September 2010, 14:55
I didn't get any private message. Anyway, the code:

barwidget.h

#ifndef BARWIDGET_H
#define BARWIDGET_H

#include <QtGui>

class BarWidget : public QWidget
{
Q_OBJECT
public:
explicit BarWidget(QWidget *parent = 0);

int value();

protected:
void paintEvent(QPaintEvent *);

signals:
void valueChanged(int);

public slots:
void setValue(int);

private:
int currentValue;
};

#endif // BARWIDGET_H

barwidget.cpp:

#include "barwidget.h"

BarWidget::BarWidget(QWidget *parent) :
QWidget(parent)
{
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();
}

void BarWidget::paintEvent(QPaintEvent *)
{
QPainter p(this);
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:
p.drawRect(QRectF( (barWidth+gapWidth)*4*width(), height()*(0/5.0), barWidth*width(), height() ));
case 4:
p.drawRect(QRectF( (barWidth+gapWidth)*3*width(), height()*(1/5.0), barWidth*width(), height() ));
case 3:
p.drawRect(QRectF( (barWidth+gapWidth)*2*width(), height()*(2/5.0), barWidth*width(), height() ));
case 2:
p.drawRect(QRectF( (barWidth+gapWidth)*1*width(), height()*(3/5.0), barWidth*width(), height() ));
case 1:
p.drawRect(QRectF( (barWidth+gapWidth)*0*width(), height()*(4/5.0), barWidth*width(), height() ));
}

p.end();
}

toro.86
15th September 2010, 15:09
thanks i sent you a private message now

MTK358
15th September 2010, 15:10
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!

wysota
15th September 2010, 15:12
I wouldn't do that for $100 :D

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.

MTK358
15th September 2010, 15:13
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?

MTK358
15th September 2010, 15:16
wysota:

I also didn't really intend on doing the whole thing for him, I already did the bar widget to show him the basics, and since it's appearant that's not all he wants, hopefully he can figure out the others after stydying my BarWidget. And I still recommend that he uses separate labels and LCD numbers (and maybe some stylesheets to make them fit in) instead of reimplementing them himself.

toro.86
15th September 2010, 15:18
tanks, I would like the widgets be separate and I need'em for a school project, i have to build a display for a bike

MTK358
15th September 2010, 15:24
OK, just create a custom widget and add some QLabels, some QLCDNumbers, and my BarWidget (which you can, of course, modify to better fit your needs) to it. If layouts won't work and the size, theme, or language will never change, then you can use absolute positioning for the widgets.

That curved bar indicator thing would be doable in the same fashion as my BarWidget did it, but it would be immensely complicated to get that curved shape, especially if you want it to stretch to any size. Maybe you can do it with pre-made images drawn using an image editor?

wysota
15th September 2010, 15:24
I'd just like to remind everyone about our 'school assignment' policy :)

toro.86
15th September 2010, 15:42
I'd just like to remind everyone about our 'school assignment' policy :)

This project is for my Display Bike help me!

toro.86
15th September 2010, 16:00
OK, just create a custom widget and add some QLabels, some QLCDNumbers, and my BarWidget (which you can, of course, modify to better fit your needs) to it. If layouts won't work and the size, theme, or language will never change, then you can use absolute positioning for the widgets.

That curved bar indicator thing would be doable in the same fashion as my BarWidget did it, but it would be immensely complicated to get that curved shape, especially if you want it to stretch to any size. Maybe you can do it with pre-made images drawn using an image editor?


can you also add the code that u sent me at my code, so in this way all can work together, because i'm not able to do this thing.

MTK358
15th September 2010, 16:14
What does the code in your original post do, and is that the functionality you want for you final application?

toro.86
15th September 2010, 16:28
What does the code in your original post do, and is that the functionality you want for you final application?


i used this application to clock the laps when i go to the racetrack and it tells me if i do a good time or not than the best lap. also it tells me the speed, the water temperature of the motor and the GPS signal for my position on the track

toro.86
15th September 2010, 16:54
I didn't get any private message. Anyway, the code:



have you recive my private message?

MTK358
15th September 2010, 17:15
Yes. So?

Should I explain more about how to make your own widget contain other widgets and how to lay them out?

toro.86
15th September 2010, 17:49
Yes. So?

Should I explain more about how to make your own widget contain other widgets and how to lay them out?

it would be great if i had more than a week time to do it...since i'd like to do it by tomorrow, could you please do it for me? i can pay you if you want"

wysota
15th September 2010, 17:53
He expects you to do his work for him.

MTK358
15th September 2010, 18:00
it would be great if i had more than a week time to do it...since i'd like to do it by tomorrow, could you please do it for me? i can pay you if you want"

It's not really fair for me to do your school assignment for you, and besides, it's against the rules of this forum.

Here are some tips:

To add a layout to a widget: widget->setLayout(layout)

Add a widget to a box layout: layout->addWidget(widget)

Add a widget to a grid layout: gridLayout->addWidget(widget, row, column)

Add a widget to a grid layout, spanning multiple cells: gridLayout->addWidget(widget, row, column, numRows, numColumns)

Add a layout to a layout: layout->addLayout(subLayout)

You can also add layouts to grid layout cells, just use addLayout() instead of addWidget().

toro.86
15th September 2010, 18:06
He expects you to do his work for him.


i know nothing about Qt and this friday i have to test my display at Monza, on my motorbike cause i'm italian. cau do it for me?

wysota
15th September 2010, 18:11
i know nothing about Qt
So why are you trying to use it?

toro.86
15th September 2010, 18:17
It's not really fair for me to do your school assignment for you, and besides, it's against the rules of this forum.

Here are some tips:

To add a layout to a widget: widget->setLayout(layout)

Add a widget to a box layout: layout->addWidget(widget)

Add a widget to a grid layout: gridLayout->addWidget(widget, row, column)

Add a widget to a grid layout, spanning multiple cells: gridLayout->addWidget(widget, row, column, numRows, numColumns)

Add a layout to a layout: layout->addLayout(subLayout)

You can also add layouts to grid layout cells, just use addLayout() instead of addWidget().

it is not for school i know nothing about Qt and this friday i have to test my display at Monza circuit, on my motorbike cause i'm italian. cau do it for me?

MTK358
15th September 2010, 18:21
OK, I misunderstood. Anyway, it doesn't look like you're trying. I told you how to lay out the widgets properly in my previous post. Do it, and then post your results.

toro.86
15th September 2010, 18:26
So why are you trying to use it?

what do u do with a display on a motorcycle for the racetrack?

wysota
15th September 2010, 19:04
I'm asking about Qt and not your "display" :)

marcvanriet
15th September 2010, 21:43
Hi,

If it is very urgent, and if it is for demonstration purposes to prove that a certain technology is working, I believe it is better to stick with the existing widgets rather than writing your own ones, even if they look more fancy.

Check out http://qt-apps.org/content/show.php/AnalogWidgets?content=87780. That widget set contains some very nice indicator widgets that could be used. If you try and use this, and run into some problems when using it, then we could help you out better.

And a second thing... if something is very urgent, it is always a very bad idea to try and use a toolkit that you are not familiar with. Stick with what you know.

Best regards,
Marc