Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Add styles to a QMessageBox
I have this code to show a message box until a time-consuming task finish.
It works but it looks ugly, example, the text doesn't seem to be centered.
Is there a way to add styles?
Or do something like this that gives me more control over how it looks?
It will react to stylesheets but i doubt you can center text.
You could make your own based on QDialog so it could any way you like.
Its not much work since you seem not to use any icons or buttons :)
Since it looks it's happening at application startup, I would go with QSplashScreen.
@SGaist Unfortunately it doesn't happen at startup. it happens in 3 moment after triggering some button
Well, you can still use it there. Or a QProgressDialog with an infinite progress bar.
@mrjj I tried doing something like
msgBox.setStylesheet("color: red;")but it didn't respond. Can you explain the other option a little more? Thanks
msgBox.setStyleSheet("background-color: rgb(255, 0, 0);");
and it should turn red.
Both QSplashScreen and QProgressDialog would also be good options as @SGaist mentions.
What i was talking about was a UI form QDialog made with the wizard.
and you get a new UI where you can add a label or other elements to make it look 100% as you wish.
If you put the same value for min and Max, you'll have an infinite bar.
What do you call "infinite bar"? I tried
progress.setMinimum(0); progress.setMaximum(0); progress.setValue(0);and in Windows got
Bonnie last edited by
Cann't you just use a QLabel to do that?
I'm using a QLabel showing "Loading" when the ui is loading for seconds.
Seems you don't need any interactive functions.
And it is easy to be customized with stylesheet.
SimonSchroeder last edited by
What do you call "infinite bar"? I tried progress.setMinimum(0); progress.setMaximum(0); progress.setValue(0); and in Windows got
I know this as "pulsing progress bar". However, you need to process incoming events occasionally in order to have that pulsating bar. The easiest (though not the preferred way) is to put QApplication::processEvents() in several places which will allow the progress dialog to update.