Multiple messages in QSplashScreen



  • I noticed that I can only show one message using 'showMessage' at a time. How can I show the application name and the status of the splashscreen at the same time without rendering a picture of the splashscreen including the application name. Here is my code so far:

    @
    QSplashScreen *splash = new QSplashScreen;
    QPixmap *splashPicture=new QPixmap(400,300);
    splashPicture->fill(Qt::lightGray);
    splash->setPixmap(*splashPicture);
    splash->show();

    Qt::Alignment center = Qt::AlignHCenter | Qt::AlignVCenter;
    splash->showMessage(QObject::tr("Application 1.0"),
                        center, Qt::black);
    
    Qt::Alignment topRight = Qt::AlignRight | Qt::AlignTop;
    splash->showMessage(QObject::tr("Setting up the main window..."),
                       topRight, Qt::black);
    

    @



  • Either add a label to QSlashScreen (e.g. by subclassing) or just create your own splash screen dialog with QtDesigner. I Recommend the latter method, because a custom splash screen should be set up within a few minutes from scratch.



  • Thank you for your advice. I even found a more comfortable method (using QPainter) to do it, by replacing lines 7-9 by:

    @
    QPainter* painter=new QPainter(splashPicture);
    painter->drawText(200,150,"Application 1.0");
    @

    The problem is now resolved for me.



  • Oh, I thought by saying
    "without rendering a picture of the splashscreen including the application name"
    You meant you don't want to do it by painting on the splash pixmap.

    Anyhow, make sure to delete the painter, or you'll get a memory leak. Better yet, create it on the stack via

    QPainter painter(&splashPicture);



  • Thanks. Well, I am a beginner, I might not express myself too well. I wanted to say, I dont want to do it in a graphic software outside Qt, so I can easily change it when I want to modify the title.



  • Pretty general approach with layouts works here too:

    @ QSplashScreen *splash = new QSplashScreen(QPixmap(QString::fromUtf8("splashscreen.png")));

    QVBoxLayout *layout = new QVBoxLayout(splash);
    layout->setAlignment(Qt::AlignCenter);
    
    QLabel *label1 = new QLabel(QString::fromUtf8("Hello, World"), splash);
    QLabel *label2 = new QLabel(QString::fromUtf8("I'm loading…"), splash);
    layout->addWidget(label1);
    layout->addWidget(label2);
    
    splash->setLayout(layout);
    splash->show();
    
    // do stuff...
    
    splash->hide();
    splash->deleteLater();@

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.