Add styles to a QMessageBox
-
I have this code to show a message box until a time-consuming task finish.
QMessageBox msgBox(pqCoreUtilities::mainWidget());
msgBox.setText("Initializing application");
msgBox.setStandardButtons(0);
msgBox.show();pqEventDispatcher::processEventsAndWait(100);
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? -
Hi
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 :) -
Hi,
Since it looks it's happening at application startup, I would go with QSplashScreen.
-
Well, you can still use it there. Or a QProgressDialog with an infinite progress bar.
-
@maria-v
Hi
Try
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.
-
@maria-v said in Add styles to a QMessageBox:
@SGaist I tried first with the progress bar but I have no way to fill it, and leaving it empty also looks bad.
Screen Shot 2020-04-29 at 15.22.47.pngIf you put the same value for min and Max, you'll have an infinite bar.
-
@maria-v said in Add styles to a QMessageBox:
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.