Display multiple Images on a nother image (e.g map with markers)
-
Hello,
I'm way of new to QT and currently looking for the required classes to create a simple window with an image as background, on which I can display multiple other small images.
Most important is that I can choose coordinates for the small images. That is to say: When I have a 1280x400 window, I would like to be able an image at exactly x=640,y=400 for the middle of the window.
Advice would be very appreciated ;)
-
Hi and welcome to devnet,
You might be interested by the "QGraphicsScene":http://qt-project.org/doc/qt-4.8/qgraphicsscene.html, "QGraphicsView":http://qt-project.org/doc/qt-4.8/qgraphicsview.html and their friends for that
Hope it helps
-
Hi,
Just in case if your want to do using QML:
- You can use "Rectangle":http://qt-project.org/doc/qt-5.0/qtquick/qml-qtquick2-rectangle.html and specify size to it.
- Then inside it you can use "Image":http://qt-project.org/doc/qt-4.8/qdeclarativeelements.html to add an image to the Rectangle.
Set Image.fillMode as per your requirement (eg. fillMode: Image.PreserveAspectFit). - After that you can added Image items as per your need and set parent to the "Rectangle" item your have added. You can then set "x" and "y" coordinates for the item.
- If you want to center the item just set the positions of the Image Items added in pt. 3 using "anchors.centerIn: parent"
-
[quote author="SGaist" date="1379587266"]Hi and welcome to devnet,
You might be interested by the "QGraphicsScene":http://qt-project.org/doc/qt-4.8/qgraphicsscene.html, "QGraphicsView":http://qt-project.org/doc/qt-4.8/qgraphicsview.html and their friends for that
Hope it helps[/quote]
Perfectly does the trick.
Just one thing: Is it possible to enforce that changes (like hiding a child object, or moving it to an other position) are repainted all at once?
Like:
window.freeze();
img1.move();
img2.move();
window.rerender(); -
You might try with setUpdatesEnabled
-
Ah, hey. Thanks a lot.
Guess there is only one last problem:
map.h
[CODE]
#include <QtWidgets/QGraphicsScene>
#include <QtWidgets/QGraphicsView>
#include <vector>class Map
{
public:
Map();private: QGraphicsScene map; QGraphicsView view;
};
[/CODE]map.cpp
[CODE]
#include "map.h"#include <QtWidgets/QGraphicsScene>
#include <QtWidgets/QGraphicsView>Map::Map()
{
this->map = QGraphicsScene(QPixmap("map.jpg"));
this->view = QGraphicsView(&this->map);
}
[/CODE]Getting the following error:
C:\Qt\Qt5.1.1\5.1.1\mingw48_32\include\QtCore\qglobal.h:946: Fehler:'QGraphicsView& QGraphicsView::operator=(const QGraphicsView&)' is private
Class &operator=(const Class &) Q_DECL_EQ_DELETE;
^ -
You can't copy QObject (the details are in the documentation)
Change map and view to pointers
-
попробуй в кьют виджет с помощью штмл решить
-
Works for me with init lists, my C++ used to be better in former days.
Getting some linker errors like:
map.cpp:-1: Fehler:undefined reference to `_imp___ZN7QWidget6resizeERK5QSize'How to properly set up the make file? Seems like QT Creator is not able to.
-
nvm, got it running.
Just seems like Qt wont allow me to continously update the map in the main thread (cause Qapp.exec() never gets called that way), and passing the map to another thread doesnt work either: "QObject::startTimer: timers cannot be started from another thread"
I guess I gotta make use of callbacks.
-
How frequently are you updating your data ? Does it take time ? If not, you could simply use a QTimer (or the timerEvent of the widget handling the map).