سؤال

How to set a specific style to a certain QMessageBox in Qt. Particularly, I would like to invoke a message box which is written below by setting a font size and color for the text "Well done!!!".

QMessageBox::information(this, "Done", "Well done!!!");
هل كانت مفيدة؟

المحلول 3

I have formated the text of the QMessageBox with HTML code. Sorry for the question. And thanks for answers.

نصائح أخرى

Using this static method you can not access QMessageBox directly, because its created and destroyed entirely inside function. But you may try to alter stylesheet property of calling object before call to this function. This means calling object should be descedant of QWidget...

something like this:

QString tmpStyleSheet=this->styleSheet();
this->setStyleSheet("style sheet for your QMessageBox");
QMessageBox::information(this, "Done", "Well done!!!");
this->setStyleSheet(tmpStyleSheet);

style of QMessageBox will inherit parent's style...

You will need to create a QMessageBox object for that particular message box and then either setStyle() or setStyleSheet(), in other words you cannot use the static helper method.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top