0

I'm trying to create a QMessageBox in form class but when I run the program,the background of message box is the same with the form class so the setStyleSheet function is not working. Here is the sample of my code :

QMessageBox msg(this);
msg.about(this,"hata","deneme");
msg.setStyleSheet(QString::fromUtf8("background-color: rgb(241, 241, 241);"));
msg.setWindowTitle("Hata");
msg.show();

Any help much appreciated.

ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97
  • I've looked at [this post](https://stackoverflow.com/questions/50222954/qmessagebox-background-and-text-color) for the python code, and I tried it on C++ with Qt. I found out that if I removed setStyleSheet("text-color: rgb()"), all of the messagebox was black, but if I left it, only the back of the icon was black. I'm not sure why that is... Then I went back to your code and found out that the `about` method probably has its own stylesheet. After pressing "ok" on the messagebox, you should get the desired color. Also, I would call `exec` instead of `show`, but I'm not sure if it does any harm –  Apr 27 '20 at 11:36
  • I'm not sure how to force the right color, but maybe you don't really need the about? There are methods to setWindowTitle etc; as you've discovered :-) –  Apr 27 '20 at 11:40
  • Thanky you so much. about function has really its own stylesheet. I removed it and now I can costomize it. – trytobedeveloper Apr 27 '20 at 15:14

0 Answers0