PDA

View Full Version : Move a image over another imge



chong_kimkeang
4th October 2012, 08:20
Hello everyone, I want to load two image at the same time when I run the program and one image can be moved by mouse over another image.8281

code_err
4th October 2012, 08:32
Look at Qt's demos. There was such an example there.

chong_kimkeang
4th October 2012, 09:03
Sorry, can you give me the link? I don't know Qt demos.

ChrisW67
4th October 2012, 22:41
The program qtdemo is part of your Qt install. I do not know which particular demo code_err is referring to though.

wysota
4th October 2012, 23:23
Hello everyone, I want to load two image at the same time when I run the program and one image can be moved by mouse over another image.8281


#include <QtGui>

int main(int argc, char **argv) {
QApplication app(argc, argv);
QGraphicsView view;
QGraphicsScene scene;
view.setScene(&scene);
QGraphicsPixmapItem *p1 = scene.addPixmap(QPixmap("px1.png"));
QGraphicsPixmapItem *p2 = scene.addPixmap(QPixmap("px2.png"));
p2->setItemFlag(QGraphicsItem::ItemIsMovable);
p2->setZValue(1);
view.show();
return app.exec();
}

chong_kimkeang
5th October 2012, 03:16
Sorry, this is my fault that I don't state this problem clearly. One of the image is the background and the other is the image that movable over the background image.
How can I do with this problem?

ChrisW67
5th October 2012, 04:45
What sort of tool are you trying to make? Is this a sort of painting tool where the foreground image is brush/region cut from another image (your earlier thread) ?

wysota
5th October 2012, 07:47
Sorry, this is my fault that I don't state this problem clearly. One of the image is the background and the other is the image that movable over the background image.
So modify the example to suit your requirements. And I don't see what's wrong with my example, one image serves as a background and the other can be moved over it.

chong_kimkeang
5th October 2012, 08:34
Yes, it will be included in my previous tool (cutting image from the brush/region) but now I just try to create this new tool in separate file because I want to make sure that the code for swiping image by mouse can work before I merge them together.

My background image is created by stylesheet("border-image: url(/bc-black-ui.png);")

So I want to have another image to be over the image background and I can swipe it to left or to right by mouse. How can I code it?

Added after 8 minutes:

To Mr.wysota, when I run the code, there is an error that 'setItemFlag' : is not a memberof 'QGraphicsPixmapItem'. What might be my problem?

Sorry for making confuse.

wysota
5th October 2012, 08:48
To Mr.wysota, when I run the code, there is an error that 'setItemFlag' : is not a memberof 'QGraphicsPixmapItem'. What might be my problem?
The method is probably called differently. Look it up in the docs.

chong_kimkeang
5th October 2012, 09:54
I try to test this code with new file, still the problem is the same.



#include "testimage.h"
#include <QApplication>
#include <QtGui>

int main(int argc, char **argv) {
QApplication app(argc, argv);
QGraphicsView view;
QGraphicsScene scene;
view.setScene(&scene);
QGraphicsPixmapItem *p1 = scene.addPixmap(QPixmap(":/C:/Users/kimkeang/Pictures/bc-black-ui.png"));
QGraphicsPixmapItem *p2 = scene.addPixmap(QPixmap(":/C:/Users/kimkeang/Pictures/blank-canvas.png"));
p2->setItemFlag(QGraphicsItem::ItemIsMovable);
p2->setZValue(1);
view.show();
return app.exec();
}


What should be the problem? (My code is written in Visual Studio 2008 and I add Qt frame work version 4.8.2 )

sonulohani
5th October 2012, 10:29
use:-


p2->setFlag(QGraphicsItem::ItemIsMovable);


instead of setItemFlag.