PDA

View Full Version : A Way To Set A Picture Without Overriding Last Picture?



AMacias
9th December 2012, 00:55
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

/**.........**/

newPlayer.setHand(newDeck.getNextCard(), newDeck.getNextCard());
playerCardCount++;
playerCardCount++;
determineHand(newPlayer.getHand(), playerCardCount);

/**.......**/


void GameModel::determineCard(int Card)
{
iRank = ( Card % 13);
if(iRank==0)
currentRank=cardAce;
else if(iRank < 9)
currentRank=static_cast<Rank>(iRank + 1);
else if(iRank == 9)
currentRank=cardTen;
else if(iRank == 10)
currentRank=cardJack;
else if(iRank == 11)
currentRank=cardQueen;
else
currentRank=cardKing;

suit = ( Card / 13 );
if(suit==0)
currentSuit=suitDiamonds;
else if(suit==1)
currentSuit=suitClubs;
else if(suit==2)
currentSuit=suitSpades;
else
currentSuit=suitHearts;

emit cardsChanged(currentSuit, currentRank);
}

void GameModel::determineHand(int *playerHand, int cardCount)
{
for(int i=0;i<cardCount;i++)
{
determineCard(playerHand[i]);
}
}

In GuiDialog.cpp


/**..........**/

gameModel = model;
playerCards = new QLabel("cards/back.jpg");

/**......**/

void GuiDialog::updateCard(int suit, int rank)
{
switch(suit)
{
case GameModel::suitDiamonds:
switch(rank)
{
case GameModel::cardAce:
ui->playerCards->setPixmap(QPixmap("cards/dace.jpg"));
break;
case GameModel::cardTwo:
ui->playerCards->setPixmap(QPixmap("cards/d2.jpg"));
break;
/**.........**/

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.

amleto
9th December 2012, 02:06
I am attempting to draw the cards on one QLabel
Why? Use three labels...

wysota
9th December 2012, 08:27
I am attempting to draw the cards on one QLabel
Why? Use three labels...

Hmm... why? Use Graphics View :)

amleto
9th December 2012, 10:28
touche


........

prof.ebral
9th December 2012, 23:48
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.

anda_skoa
10th December 2012, 12:30
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,
_