LaTj
6th November 2013, 23:56
I recently found a way to highlight a pixmap, now I need to highlight while the mouse cursor is positioned on it. Also, I need to click on these pixmap images.
My problem is that I have no idea how to do this. Some people suggest to subclass QLabel. If someone could lead me to the right direction please.
Here is my code
#include <QtWidgets>
#include <string>
using std::string;
#include "canvas.h"
#include "player.h"
#include "computer.h"
Canvas::Canvas(QWidget *parent) : QWidget(parent)
{
cardTable = new QListView;
startButton = new QPushButton("Start");
startButton->setFixedWidth(100);
connect(startButton, SIGNAL(clicked()), this, SLOT(startClicked()));
QVBoxLayout *verticalLayout = new QVBoxLayout;
verticalLayout->addWidget(cardTable);
verticalLayout->addWidget(startButton);
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addLayout(verticalLayout, 0, 0, 1, 1);
setLayout(mainLayout);
setUpComputerIcons();
setUpDeckIcons();
myGame = new Game(this);
}
void Canvas::setUpPlayerIcons(string *pString)
{
QPixmap qpx;
QSize iconSize;
string str;
for (int i = 0; i < MAXCARDS; i++)
{
shadow = new QGraphicsDropShadowEffect(this);
shadow->setBlurRadius(10);
cardIconPlayer[i] = new QLabel(cardTable);
str = pString[i];
qpx = QPixmap(str.c_str());
iconSize = qpx.size();
iconSize.scale(190, 276, Qt::KeepAspectRatio);
QPixmap scaledImage = qpx.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
cardIconPlayer[i]->setPixmap(scaledImage);
cardIconPlayer[i]->move(20 + 60 * i, 350);
cardIconPlayer[i]->setGraphicsEffect(shadow);
playerPixmaps.push_back(scaledImage);
}
}
My problem is that I have no idea how to do this. Some people suggest to subclass QLabel. If someone could lead me to the right direction please.
Here is my code
#include <QtWidgets>
#include <string>
using std::string;
#include "canvas.h"
#include "player.h"
#include "computer.h"
Canvas::Canvas(QWidget *parent) : QWidget(parent)
{
cardTable = new QListView;
startButton = new QPushButton("Start");
startButton->setFixedWidth(100);
connect(startButton, SIGNAL(clicked()), this, SLOT(startClicked()));
QVBoxLayout *verticalLayout = new QVBoxLayout;
verticalLayout->addWidget(cardTable);
verticalLayout->addWidget(startButton);
QGridLayout *mainLayout = new QGridLayout;
mainLayout->addLayout(verticalLayout, 0, 0, 1, 1);
setLayout(mainLayout);
setUpComputerIcons();
setUpDeckIcons();
myGame = new Game(this);
}
void Canvas::setUpPlayerIcons(string *pString)
{
QPixmap qpx;
QSize iconSize;
string str;
for (int i = 0; i < MAXCARDS; i++)
{
shadow = new QGraphicsDropShadowEffect(this);
shadow->setBlurRadius(10);
cardIconPlayer[i] = new QLabel(cardTable);
str = pString[i];
qpx = QPixmap(str.c_str());
iconSize = qpx.size();
iconSize.scale(190, 276, Qt::KeepAspectRatio);
QPixmap scaledImage = qpx.scaled(iconSize, Qt::KeepAspectRatio, Qt::SmoothTransformation);
cardIconPlayer[i]->setPixmap(scaledImage);
cardIconPlayer[i]->move(20 + 60 * i, 350);
cardIconPlayer[i]->setGraphicsEffect(shadow);
playerPixmaps.push_back(scaledImage);
}
}