Results 1 to 12 of 12

Thread: Move a image over another imge

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Sep 2012
    Posts
    66
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Question Move a image over another imge

    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.Capture.jpg

  2. #2
    Join Date
    Sep 2011
    Posts
    86
    Thanks
    4
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Windows

    Default Re: Move a image over another imge

    Look at Qt's demos. There was such an example there.

  3. #3
    Join Date
    Sep 2012
    Posts
    66
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Move a image over another imge

    Sorry, can you give me the link? I don't know Qt demos.

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Move a image over another imge

    The program qtdemo is part of your Qt install. I do not know which particular demo code_err is referring to though.

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Move a image over another imge

    Quote Originally Posted by chong_kimkeang View Post
    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.Capture.jpg
    Qt Code:
    1. #include <QtGui>
    2.  
    3. int main(int argc, char **argv) {
    4. QApplication app(argc, argv);
    5. view.setScene(&scene);
    6. QGraphicsPixmapItem *p1 = scene.addPixmap(QPixmap("px1.png"));
    7. QGraphicsPixmapItem *p2 = scene.addPixmap(QPixmap("px2.png"));
    8. p2->setItemFlag(QGraphicsItem::ItemIsMovable);
    9. p2->setZValue(1);
    10. view.show();
    11. return app.exec();
    12. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  6. The following user says thank you to wysota for this useful post:

    chong_kimkeang (5th October 2012)

  7. #6
    Join Date
    Sep 2012
    Posts
    66
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Move a image over another imge

    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?
    Last edited by chong_kimkeang; 5th October 2012 at 03:23.

  8. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Move a image over another imge

    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) ?

  9. The following user says thank you to ChrisW67 for this useful post:

    chong_kimkeang (5th October 2012)

  10. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Move a image over another imge

    Quote Originally Posted by chong_kimkeang View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  11. The following user says thank you to wysota for this useful post:

    chong_kimkeang (5th October 2012)

  12. #9
    Join Date
    Sep 2012
    Posts
    66
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Move a image over another imge

    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.
    Last edited by chong_kimkeang; 5th October 2012 at 08:39.

  13. #10
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,368
    Thanks
    3
    Thanked 5,017 Times in 4,793 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Move a image over another imge

    Quote Originally Posted by chong_kimkeang View Post
    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  14. #11
    Join Date
    Sep 2012
    Posts
    66
    Thanks
    21
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Windows

    Default Re: Move a image over another imge

    I try to test this code with new file, still the problem is the same.

    Qt Code:
    1. #include "testimage.h"
    2. #include <QApplication>
    3. #include <QtGui>
    4.  
    5. int main(int argc, char **argv) {
    6. QApplication app(argc, argv);
    7. view.setScene(&scene);
    8. QGraphicsPixmapItem *p1 = scene.addPixmap(QPixmap(":/C:/Users/kimkeang/Pictures/bc-black-ui.png"));
    9. QGraphicsPixmapItem *p2 = scene.addPixmap(QPixmap(":/C:/Users/kimkeang/Pictures/blank-canvas.png"));
    10. p2->setItemFlag(QGraphicsItem::ItemIsMovable);
    11. p2->setZValue(1);
    12. view.show();
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

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

  15. #12
    Join Date
    May 2012
    Location
    Bangalore, India
    Posts
    271
    Thanks
    29
    Thanked 50 Times in 47 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Move a image over another imge

    use:-
    Qt Code:
    1. p2->setFlag(QGraphicsItem::ItemIsMovable);
    To copy to clipboard, switch view to plain text mode 

    instead of setItemFlag.
    Heavy Metal Rules. For those about to rock, we salute you.
    HIT THANKS IF I HELPED.

  16. The following user says thank you to sonulohani for this useful post:

    chong_kimkeang (5th October 2012)

Similar Threads

  1. Replies: 3
    Last Post: 3rd August 2012, 10:35
  2. how to move the image in QLabel
    By augusbas in forum Qt Programming
    Replies: 1
    Last Post: 13th October 2010, 08:33
  3. Problem in Move Move Event Handler.
    By redgoof in forum Qt Programming
    Replies: 0
    Last Post: 7th April 2010, 11:45
  4. how can we move an image?
    By sh123 in forum Qt Programming
    Replies: 4
    Last Post: 24th January 2009, 12:46
  5. Move Rectangle on mouse Move
    By vermarajeev in forum Qt Programming
    Replies: 24
    Last Post: 14th May 2007, 05:34

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.