QSplashScreen をサブクラス化して a のQProgressBar
中に入れています。QSplashScreen
メソッドをオーバーライドしますdrawContents()
。
ジオメトリを正しく設定したと思っていましたが、画面の上部と下部の両方にレンダリングされます。どうしてか分かりません。合わせ方は他にもあるのではないでしょうか。画像は 380x284 であるため、数値は正しいため、高さ 19 のプログレス バーは 265 ピクセル下になるはずです。
印刷画面ボタンでスプラッシュ スクリーンが表示されませんでした。現時点では 1 色の白いスプラッシュ スクリーンですが、ご覧のとおり、上下にプログレス バーがあります (どちらも同じ色で、カメラからの照明です)。
もう 1 つの問題はshowMessage()
、QSplashScreen のメソッドです。メッセージをプログレスバーの上に右揃えで表示したい...誰かがそれを行う方法を知っているなら。
スプラッシュスクリーン.cpp
#include "splashscreen.h"
SplashScreen::SplashScreen(QApplication *app, QWidget *parent) :
QSplashScreen(parent)
{
this->app = app;
this->setPixmap(QPixmap(":/images/splashscreen.png"));
this->setCursor(Qt::BusyCursor);
// if I dont make it a child, it *only* renders at the top
progress = new QProgressBar(this);
progress->setGeometry(0, 265, 380, 19); // puts it at bottom
progress->setAlignment(Qt::AlignHCenter | Qt::AlignVCenter);
progress->setValue(0);
progress->setMaximum(100);
progress->setEnabled(true);
this->showMessage("Hello", Qt::AlignBottom);
connect(progress, SIGNAL(valueChanged(int)), this, SLOT(progressBarUpdated(int)));
}
void SplashScreen::drawContents(QPainter *painter)
{
QSplashScreen::drawContents(painter);
this->progress->render(painter);
}
void SplashScreen::progressBarUpdated(int value)
{
this->repaint();
this->app->processEvents();
}
スプラッシュスクリーン.h
#ifndef SPLASHSCREEN_H
#define SPLASHSCREEN_H
#include <QSplashScreen>
#include <QProgressBar>
#include <QApplication>
class SplashScreen : public QSplashScreen
{
Q_OBJECT
public:
explicit SplashScreen(QApplication *app, QWidget *parent = 0);
QProgressBar *progress;
QWidget *spacer;
QApplication *app;
public slots:
void progressBarUpdated(int value);
protected:
void drawContents(QPainter *painter);
};
#endif // SPLASHSCREEN_H
main.cpp
#include <QtGui/QApplication>
#include <time.h>
#include "splashscreen.h"
#include "mainwindow.h"
int main(int argc, char *argv[])
{
srand(time(0));
QApplication a(argc, argv);
SplashScreen *splash = new SplashScreen(&a);
splash->show();
// snip.. loading a ton of stuff into memory at startup
// if you're testing this you might have to sleep/timer here iono
MainWindow w;
splash->finish(&w);
w.show();
return app.exec();
}