Results 1 to 6 of 6

Thread: Display images and move them

  1. #1
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Display images and move them

    Hello,
    I am developing a checkers game for Mac and Win.
    I am displaying each piece in a QLabel in the following way
    Qt Code:
    1. QLabel *piece = new QLabel("piece",this);
    2. piece->setPixmap(QPixmap("piece.png"));
    To copy to clipboard, switch view to plain text mode 
    Now I have to display kings and I would like to overlap two images (piece.png) in the same QLabel because I have to move the two pieces (king) together in my animations. How can I do that?

    Tx a lot!!

  2. #2
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display images and move them

    I guess graphics view framework is suitable for your need.
    Have a look at QGraphicsViewand QGraphicsSceneand QGraphicsPixmapItem

  3. #3
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Display images and move them

    tx a lot for your help aamer4yu. I am doing as you suggested. This is the code (in progress)...

    Qt Code:
    1. lPixmap.load("piece.png");
    2. scene->addPixmap(lPixmap);
    3. ui_graphicsView->setScene(scene);
    4. ui_graphicsView->show();
    5. ui_graphicsView->adjustSize();
    To copy to clipboard, switch view to plain text mode 

    By the way I still have 2 questions:

    1) I noticed that the QGraphicsView is not transparent. Is it possible to apply transaprency?
    2) is it possible to add a second image to the scene with a different y coordinate?

    Tx

  4. #4
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Display images and move them

    hello,
    just solved point 1:

    Qt Code:
    1. ui_graphicsView->setStyleSheet("background: transparent");
    To copy to clipboard, switch view to plain text mode 

    still looking at point 2....

  5. #5
    Join Date
    Feb 2010
    Posts
    10
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60

    Default Re: Display images and move them

    found the solution for the second point too!
    This is the code.

    Qt Code:
    1. QGraphicsScene *scene = new QGraphicsScene(this);
    2. QPixmap lPixmap;
    3. lPixmap.load("piece.png");
    4. scene->addPixmap(lPixmap);
    5. //add the second item
    6. QGraphicsPixmapItem *test = scene->addPixmap(lPixmap);
    7. //and set its offset
    8. test->setOffset(0,-6);
    9. ui_graphicsView->setScene(scene);
    10. ui_graphicsView->show();
    11. ui_graphicsView->adjustSize();
    To copy to clipboard, switch view to plain text mode 

    Cheers!!

  6. #6
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Display images and move them

    Am doubtful if using offset is the right way to go...
    test is a QGraphicsPixmapItem and you can set its position in the scene... [QGraphicsItem::setPos]

Similar Threads

  1. Display images and move them
    By AL in forum General Programming
    Replies: 2
    Last Post: 11th February 2010, 11:15
  2. Application doesn't display images
    By satoshi in forum Qt Programming
    Replies: 3
    Last Post: 2nd January 2010, 11:33
  3. Move QT Window to different x display
    By jbpvr in forum Qt Programming
    Replies: 1
    Last Post: 5th September 2007, 20:28
  4. Display Images in QGraphicsView
    By robertaandrews in forum Qt Tools
    Replies: 4
    Last Post: 15th May 2007, 18:35
  5. how to display full tree item name on mouse move ?
    By rajesh in forum Qt Programming
    Replies: 5
    Last Post: 15th November 2006, 08:41

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.