I am trying to make a simple card game, and I want to highlight some card pixmap images as my mouse hovers over it. Then I want to click on that card. But, lets take it one thing at a time. How would I highlight those cards, I really do not have any clue?

By the way, I use QLabel to make the pixmaps.

Here is the code, displaying my constructor and the function where I map the images.

Qt Code:
  1. #include <QtWidgets>
  2. #include <string>
  3.  
  4. using std::string;
  5.  
  6. #include "canvas.h"
  7. #include "player.h"
  8. #include "computer.h"
  9.  
  10. Canvas::Canvas(QWidget *parent) : QWidget(parent)
  11. {
  12. cardTable = new QListView;
  13.  
  14. startButton = new QPushButton("Start");
  15. startButton->setFixedWidth(100);
  16.  
  17. connect(startButton, SIGNAL(clicked()), this, SLOT(startClicked()));
  18. connect(cardTable, SIGNAL(clicked(QModelIndex)), this, SLOT(currentCard(const QModelIndex &)));
  19.  
  20. QVBoxLayout *verticalLayout = new QVBoxLayout;
  21. verticalLayout->addWidget(cardTable);
  22. verticalLayout->addWidget(startButton);
  23.  
  24. QGridLayout *mainLayout = new QGridLayout;
  25. mainLayout->addLayout(verticalLayout, 0, 0, 1, 1);
  26.  
  27. setLayout(mainLayout);
  28.  
  29. setUpComputerIcons();
  30. setUpDeckIcons();
  31.  
  32. myGame = new Game(this);
  33. }
  34.  
  35. void Canvas::setUpPlayerIcons(string *pString)
  36. {
  37. QPixmap qpx;
  38. QSize iconSize;
  39. string str;
  40.  
  41. for (int i = 0; i < MAXCARDS; i++)
  42. {
  43. cardIconPlayer[i] = new QLabel(cardTable);
  44. str = pString[i];
  45. qpx = QPixmap(str.c_str());
  46. iconSize = qpx.size();
  47. iconSize.scale(190, 276, Qt::KeepAspectRatio);
  48. QPixmap scaledImage = qpx.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
  49. cardIconPlayer[i]->setPixmap(scaledImage);
  50. cardIconPlayer[i]->move(20 + 60 * i, 350);
  51. }
  52.  
  53. }
To copy to clipboard, switch view to plain text mode