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]);
}
}
/**.........**/
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]);
}
}
To copy to clipboard, switch view to plain text mode
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;
/**.........**/
/**..........**/
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;
/**.........**/
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.
Bookmarks