错误是: 没有匹配函数来调用' Game :: drawPanel(int,int,int,int,Qt :: GlobalColor)' drawPanel(0,0,150,768,Qt的::深青绿); ^
我是Qt的新人,我开始制作游戏。我正在关注youtube教程,我无法找到代码中的错误。它的不透明度问题,但在视频,家伙没有提供这个论点,它的确有效。
Game.h
#ifndef GAME_H
#define GAME_H
#include <QGraphicsView>
#include <QGraphicsScene>
#include "Interface.h"
class Game: public QGraphicsView{
Q_OBJECT
public:
// constructors
Game(QWidget* parent=NULL);
// public methods
void displayMainMenu();
QString getWhosTurn();
void setWhosTurn(QString player);
// public attributes
QGraphicsScene* scene;
Interface* interface;
QString* fight; // wskaźnik??
public slots:
void start();
private:
void drawPanel(int x, int y, int width, int height, QColor color, double opacity);
void drawGUI();
QString whosTurn_;
QGraphicsTextItem* whosTurnText;
};
#endif //GAME_H
Game.cpp
#include "Game.h"
#include "Interface.h"
#include "Button.h"
#include <QGraphicsTextItem>
Game::Game (QWidget *parent){
// set up the screen
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFixedSize(1024,768);
// set up the scene
scene = new QGraphicsScene();
scene->setSceneRect(0,0,1024,768);
setScene(scene);
}
void Game::start(){
// clear the screen
scene->clear();
interface = new Interface();
interface->placeHexes();
}
void Game::drawPanel(int x, int y, int width, int height, QColor color, double opacity){
// draws a panel at the specified location with the specified properties
QGraphicsRectItem* panel = new QGraphicsRectItem(x,y,width,height);
QBrush brush;
brush.setStyle(Qt::SolidPattern);
brush.setColor(color);
panel->setBrush(brush);
panel->setOpacity(opacity);
scene->addItem(panel);
}
void Game::drawGUI(){
// draw the left panel
drawPanel(0,0,150,768,Qt::darkCyan);
// draw the right panel
drawPanel(874,0,150,768,Qt::darkCyan);
// place player1 text
QGraphicsTextItem* p1 = new QGraphicsTextItem("Tekst roboczy 1");
p1->setPos(25,0);
scene->addItem(p1);
// place player2 text
QGraphicsTextItem* p2 = new QGraphicsTextItem("Tekst roboczy 2");
p2->setPos(874+25,0);
scene->addItem(p2);
// place whosTurnText
whosTurnText = new QGraphicsTextItem();
setWhosTurn(QString("PLAYER1"));
whosTurnText->setPos(490,0);
scene->addItem(whosTurnText);
}
void Game::displayMainMenu(){
// create the title text
QGraphicsTextItem* titleText = new QGraphicsTextItem(QString("RockPaperScisors?"));
QFont titleFont("comic sans",50);
titleText->setFont(titleFont);
int txPos = this->width()/2 - titleText->boundingRect().width()/2;
int tyPos = 150;
titleText->setPos(txPos,tyPos);
scene->addItem(titleText);
// create the Multiplayer button
Button* multiplayerButton = new Button(QString("Multiplayer"));
int bxPos = this->width()/2 - multiplayerButton->boundingRect().width()/2;
int byPos = 275;
multiplayerButton->setPos(bxPos,byPos);
connect(multiplayerButton,SIGNAL(clicked()),this,SLOT(start()));
scene->addItem(multiplayerButton);
// create the quit button
Button* quitButton = new Button(QString("Quit"));
int qxPos = this->width()/2 - quitButton->boundingRect().width()/2;
int qyPos = 350;
quitButton->setPos(qxPos,qyPos);
connect(quitButton,SIGNAL(clicked()),this,SLOT(close()));
scene->addItem(quitButton);
}
QString Game::getWhosTurn(){
return whosTurn_;
}
void Game::setWhosTurn(QString player){
// change the QString
whosTurn_ = player;
// change the QGraphicsTextItem
whosTurnText->setPlainText(QString("Whos turn: ") + player);
}