【发布时间】:2019-01-08 20:02:59
【问题描述】:
我有一个带有启动画面的应用程序。我需要在主窗口出现之前显示启动画面并等待 3.5 秒。现在完成后,我需要显示主窗口。
这是我尝试过的代码,
#include <QApplication>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QTimer>
#include "game.h"
#include "player.h"
#include <QSplashScreen>
#include <QObject>
Game *game;
int main(int argc, char *argv[])
{
//Splash screen
QApplication a(argc, argv);
QSplashScreen *splash = new QSplashScreen;
splash->setPixmap(QPixmap(":/images/Images/1.JPG"));
splash->show();
//main window
game = new Game();
QTimer::singleShot(3500, splash, SLOT(close()));
QTimer::singleShot(3500, game, SLOT(show()));
game->displayHome();
return a.exec();
}
游戏类
Game::Game(QWidget *parent)
{
scene = new QGraphicsScene();
scene->setSceneRect(0,0,800,600);
setBackgroundBrush(QBrush(QImage("img.png")));
setScene(scene);
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
setFixedSize(800,600);
show();
qDebug() << "yoyoyoy";
score = new Score();
health = new Health();
connect(this->health,SIGNAL(crash()),this,SLOT(gameover3()));
}
void Game::displayHome()
{
logo = new Logo();
scene->addItem(logo);
playButton = new Menubuttons(QString("Play"));
int bxPos = this->width()/2 - playButton->boundingRect().width()/2;
int byPos = 275;
playButton->setPos(bxPos,byPos);
connect(playButton,SIGNAL(clicked()),this,SLOT(startGame()));
scene->addItem(playButton);
instructions = new Menubuttons(QString("Instructions"));
int axPos = this->width()/2 - instructions->boundingRect().width()/2;
int ayPos = 350;
instructions->setPos(axPos,ayPos);
connect(instructions,SIGNAL(clicked()),this,SLOT(instruct()));
scene->addItem(instructions);
quitButton = new Menubuttons(QString("Quit"));
int qxPos = this->width()/2 - quitButton->boundingRect().width()/2;
int qyPos = 425;
quitButton->setPos(qxPos,qyPos);
connect(quitButton,SIGNAL(clicked()),this,SLOT(close()));
scene->addItem(quitButton);
scene->removeItem(inst);
}
但它同时出现。我该如何解决?
【问题讨论】:
-
@eyllanesc 哦,对不起,先生。我还是没查。我会检查并让您知道先生。感谢您的回答先生
-
@eyllanesc 先生,它不工作。
diaplayHome()是 Game 类中的一个方法。它初始化需要在窗口中打开的 UI。先生,我正在制作游戏 -
然后提供minimal reproducible example,显示你的游戏类。
-
@eyllanesc 我添加了游戏类。先生,你能检查一下吗?