2012-10-02 4 views
3

QSplashScreen을 서브 클래 싱하여 QProgressBarQSplashScreen 안에 넣고 있습니다. 이 메소드는 drawContents() 메소드보다 우선합니다.QSplashScreen 내에서 QProgressBar 정렬

형상을 올바르게 설정했다고 생각했지만 화면의 상단과 하단 모두에서 렌더링됩니다. 나는 이유를 모른다. 아마도 그것을 조정하는 또 다른 방법이있을 것입니다. 이미지의 크기가 380x284이므로 숫자가 정확하므로 19 높이 진행 막대가 265 픽셀 아래에 있어야합니다.

엉터리 사진으로 불편을 끼쳐 드려 죄송합니다. 인쇄 화면 버튼으로 시작 화면이 표시되지 않았습니다. 지금은 단 1 색상의 흰색 스플래시 화면이지만 볼 수 있듯이 위쪽과 아래쪽의 진행률 표시 줄 (둘 다 같은 색, 즉 카메라의 조명)입니다.

http://i.imgur.com/p1LoJ.jpg

또 다른 문제는 QSplashScreen의 showMessage() 방법이 될 것입니다. 진행 표시 줄 위에 메시지를 표시하고 오른쪽 정렬하면됩니다. 누군가가 그 일을하는 방법을 알고 있다면.

splashscreen.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(); 
} 

splashscreen.h 당신은 QProgressBar을 만들지 않고, 직접 진행을 그릴 수

#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(); 
} 

답변

3

. 예를 들어 :

sp.h :

#ifndef SPLASHSCREEN_H 
#define SPLASHSCREEN_H 

#include <QSplashScreen> 
#include <QApplication> 

class SplashScreen : public QSplashScreen 
{ 
    Q_OBJECT 
public: 
    explicit SplashScreen(QApplication *app, QWidget *parent = 0); 
    int m_progress; 
    QApplication *app; 

public slots: 
    void setProgress(int value) 
    { 
     m_progress = value; 
     if (m_progress > 100) 
     m_progress = 100; 
     if (m_progress < 0) 
     m_progress = 0; 
     update(); 
    } 

protected: 
    void drawContents(QPainter *painter); 

}; 

#endif // SPLASHSCREEN_H 

sp.cpp

#include "sp.h" 

SplashScreen::SplashScreen(QApplication *aApp, QWidget *parent) : 
    QSplashScreen(parent), app(aApp), m_progress(0) 

{ 
    this->setPixmap(QPixmap(":/images/splashscreen.png")); 
    this->setCursor(Qt::BusyCursor); 

    this->showMessage("Hello", Qt::AlignBottom); 
} 

void SplashScreen::drawContents(QPainter *painter) 
{ 
    QSplashScreen::drawContents(painter); 

    // Set style for progressbar... 
    QStyleOptionProgressBarV2 pbstyle; 
    pbstyle.initFrom(this); 
    pbstyle.state = QStyle::State_Enabled; 
    pbstyle.textVisible = false; 
    pbstyle.minimum = 0; 
    pbstyle.maximum = 100; 
    pbstyle.progress = m_progress; 
    pbstyle.invertedAppearance = false; 
    pbstyle.rect = QRect(0, 265, 380, 19); // Where is it. 

    // Draw it... 
    style()->drawControl(QStyle::CE_ProgressBar, &pbstyle, painter, this); 
} 

이 당신을하는 데 도움이 될 수 있습니다.