Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8609263
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T03:50:33+00:00 2026-06-12T03:50:33+00:00

I am putting a QProgressBar inside a QSplashScreen by subclassing QSplashScreen. It overrides the

  • 0

I am putting a QProgressBar inside a QSplashScreen by subclassing QSplashScreen. It overrides the drawContents() method.

I thought I had set the geometry correctly, but it renders at both the top and bottom of the screen. I don’t know why. Perhaps there’s another way to align it. The numbers are correct, as the image is 380×284, so a 19 height progress bar should be 265 pixels down.

Sorry for crappy picture, splash screen wasn’t showing up with print screen button. It’s just a 1 color white splash screen at the moment, but as you can see, progress bar at top and bottom (they’re both the same colors, its the lighting from the camera).

https://i.stack.imgur.com/aEtWk.jpg

Another issue will be the showMessage() method of QSplashScreen. I want the message to appear above the progress bar, right-aligned… if anyone has any ideas how to do that.

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

#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();
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T03:50:34+00:00Added an answer on June 12, 2026 at 3:50 am

    You can paint progress directly, without creating QProgressBar. For example:

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

    May be this helps you.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm putting html variable inside php var but they aren't escaped correctly so I
I putting together a page that will display a set of stored values. I
Putting a precompiled regex inside two different hashes referenced in a list: my @list
I am putting server side validation but seems it's not working in the way
I'm putting an DOMpdf creator in my Codeigniter application, but now i need to
I'm putting a input inside a a-tag, and I want to stop the link
I'm putting a UISegmentedControl and UIBarButtonItem inside of a UIToolBar with the following code:
Normally i'm putting only important link inside my sitemap which right now they are
I am putting inner join in my query.I have got the result but didn't
Putting radio buttons in a fieldset with data-role=controlgroup , jquery-mobile renders them like an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.