Results 1 to 6 of 6

Thread: A Way To Set A Picture Without Overriding Last Picture?

  1. #1
    Join Date
    Dec 2012
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default A Way To Set A Picture Without Overriding Last Picture?

    Hi qtcentre.org,

    I am attempting to set a picture using QLabel. I will include the functions I use to do the operations then explain the problem:

    GameModel.cpp
    Qt Code:
    1. /**.........**/
    2.  
    3. newPlayer.setHand(newDeck.getNextCard(), newDeck.getNextCard());
    4. playerCardCount++;
    5. playerCardCount++;
    6. determineHand(newPlayer.getHand(), playerCardCount);
    7.  
    8. /**.......**/
    9.  
    10.  
    11. void GameModel::determineCard(int Card)
    12. {
    13. iRank = ( Card % 13);
    14. if(iRank==0)
    15. currentRank=cardAce;
    16. else if(iRank < 9)
    17. currentRank=static_cast<Rank>(iRank + 1);
    18. else if(iRank == 9)
    19. currentRank=cardTen;
    20. else if(iRank == 10)
    21. currentRank=cardJack;
    22. else if(iRank == 11)
    23. currentRank=cardQueen;
    24. else
    25. currentRank=cardKing;
    26.  
    27. suit = ( Card / 13 );
    28. if(suit==0)
    29. currentSuit=suitDiamonds;
    30. else if(suit==1)
    31. currentSuit=suitClubs;
    32. else if(suit==2)
    33. currentSuit=suitSpades;
    34. else
    35. currentSuit=suitHearts;
    36.  
    37. emit cardsChanged(currentSuit, currentRank);
    38. }
    39.  
    40. void GameModel::determineHand(int *playerHand, int cardCount)
    41. {
    42. for(int i=0;i<cardCount;i++)
    43. {
    44. determineCard(playerHand[i]);
    45. }
    46. }
    To copy to clipboard, switch view to plain text mode 

    In GuiDialog.cpp
    Qt Code:
    1. /**..........**/
    2.  
    3. gameModel = model;
    4. playerCards = new QLabel("cards/back.jpg");
    5.  
    6. /**......**/
    7.  
    8. void GuiDialog::updateCard(int suit, int rank)
    9. {
    10. switch(suit)
    11. {
    12. case GameModel::suitDiamonds:
    13. switch(rank)
    14. {
    15. case GameModel::cardAce:
    16. ui->playerCards->setPixmap(QPixmap("cards/dace.jpg"));
    17. break;
    18. case GameModel::cardTwo:
    19. ui->playerCards->setPixmap(QPixmap("cards/d2.jpg"));
    20. break;
    21. /**.........**/
    To copy to clipboard, switch view to plain text mode 

    So as you can see I left out a huge part of my code, only including the necessary parts(atleast that I think) necessary to help me answer my question. I am developing a GUI to play a casino game called Baccarat. I am attempting to draw the cards on one QLabel, in which I would really like for one card to display one right next to the each other. However, when I run it, it draws a card one right on top of the other. I was wondering if there is a way to be able to do that as opposed to making 3 extra signals for 3 extra slots to display 3 extra cards which will require 3 different updateCard functions. I hope I have made myself as clear as possible and if you would like for me to include any more code, please let me know and I will. I just don't want my post to be monstrously long.

    Thank you for your time and help.

  2. #2
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A Way To Set A Picture Without Overriding Last Picture?

    I am attempting to draw the cards on one QLabel
    Why? Use three labels...
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

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

    Default Re: A Way To Set A Picture Without Overriding Last Picture?

    Quote Originally Posted by amleto View Post
    I am attempting to draw the cards on one QLabel
    Why? Use three labels...
    Hmm... why? Use Graphics View
    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.


  4. #4
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: A Way To Set A Picture Without Overriding Last Picture?

    touche


    ........
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  5. #5
    Join Date
    Feb 2010
    Posts
    96
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: A Way To Set A Picture Without Overriding Last Picture?

    If you are insistent on using one QLabel you can create a QImage and paint both images side by side, then return the QImage as a QPixmap and use that to set the QLabel's QPixmap. Personally, I'm in the QGraphicsView boat.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: A Way To Set A Picture Without Overriding Last Picture?

    I would even go so far as to suggest looking into the QML extension of QGraphicsView (QtQuick), as it adds easy access to all kinds of animations of elements which I would guess a game could make good use of.

    Cheers,
    _

Similar Threads

  1. Replies: 3
    Last Post: 8th March 2012, 23:51
  2. How to create PIP (Picture In Picture) on QwebView
    By luckychap in forum Qt Programming
    Replies: 0
    Last Post: 18th July 2011, 12:47
  3. Getting Chart as picture
    By codeman in forum Qt Programming
    Replies: 4
    Last Post: 24th November 2009, 12:39
  4. Picture on a button
    By zgulser in forum Qt Tools
    Replies: 4
    Last Post: 13th January 2009, 04:03
  5. resize a picture
    By omega36 in forum Qt Programming
    Replies: 2
    Last Post: 9th January 2009, 14: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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.