PDA

View Full Version : Using maps in QT



SpiceWeasel
19th May 2016, 23:43
Hello,

I am looking for example code and/or tutorials about rendering maps using a QT widget (like open street maps) and showing how to programmatically add points of interest to the map at specified coordinates.

Ideally, I'd like to create an app that shows a city map with points of interest that I have listed in a database. When you click on the point of interest on the map, either a widget or map-overlay pops up with information about the PoI.

I know how to design standard GUI using QT, but I have no clue how to start something like what I am looking for.

TIA

d_stranz
20th May 2016, 00:44
Did you see the other thread here (http://www.qtcentre.org/threads/66063-LNK1181-cannot-open-input-file-obj-filename-obj) about QMapControl? Has a link to the web site. Looks like the control may support all that you've mentioned and will save you some work.

SpiceWeasel
23rd May 2016, 19:35
Did you see the other thread here (http://www.qtcentre.org/threads/66063-LNK1181-cannot-open-input-file-obj-filename-obj) about QMapControl? Has a link to the web site. Looks like the control may support all that you've mentioned and will save you some work.

Thanks. It appears to have exactly what I am looking for!

SpiceWeasel
24th May 2016, 20:19
QMapControl is a great tool, but I've come across something I don't quite understand... it seems that QMapControl is not a complete(?) widget. If you try to use it by itself, it doesn't display itself properly; but if you embed it another widget (as all the examples do), it works fine. Is that by design?

Examining the QMapControl class, I found that it has neither a sizeHint() overload, nor a resizeEvent() overload. Aren't those functions customarily overloaded for custom widgets?

d_stranz
30th May 2016, 17:25
Examining the QMapControl class, I found that it has neither a sizeHint() overload, nor a resizeEvent() overload. Aren't those functions customarily overloaded for custom widgets?

Not necessarily. Typically, if a widget is used within a layout, the layout will take responsibility for the widget's size. The sizeHint helps the layout do this by providing a recommended size. In the default implementation, an invalid size is returned. The resizeEvent eventually triggers a paintEvent, so my guess is whatever rescaling the map control does is performed in its paint event instead.

I am not sure what you mean by "use it by itself". If you aren't embedding it in a layout or in a resizable parent, it will be created with whatever default size it has, and there isn't any way to resize it except through code. Naked QWidgets don't have size grips. They need to be embedded into a parent that does (QMainWindow, QDialog, etc.)

Sorry for the delay in reply. Something is causing the forum URL to be inaccessible - a DNS problem, DOS attack, don't know. It's been 5 days since I was able to last access the site.