PDA

View Full Version : setting background color of QMessageBox



wagmare
23rd May 2009, 11:45
hi friends,
i am using QMessageBox to dispaly warning if the user press a pushButton ..
i coded like this:


QMessageBox msgBox;

int ret = QMessageBox::warning(this, tr("My Application"),
tr("<font color = red >Are you sure you want to quit?.\n"
"Shut Down key is pressed </font >"),
QMessageBox::Ok | QMessageBox::Cancel);

msgBox.setStyleSheet(QString::fromUtf8("background-color: rgb(241, 241, 241);"));
switch (ret) {
case QMessageBox::Ok :
qApp->quit();
break;

case QMessageBox::Cancel :
break;

default :
break;

}

rendered using the default stylesheet of app .. it is pure black in background color ..
the text are not visible ... so i use <font > in constructor of QMessage::warning ..

but i cant set font color of buttons ... yes , no text were not visible ...

i try change the background color of QMessageBox .. but QPalette and StyleSheet is not working ... please help ...
how to set backgroud color or color of the text in QMessage::standardButton()

aamer4yu
23rd May 2009, 12:07
Have you set some global stylesheet on your application ?
Also in your code, it is useless to have msgBox, since you are actually calling message box thru one of the static functions of QMessageBox.
Try setting stylesheet for QMessageBox in the application.

See assistant How to style QMessageBox. You can find it under Qt StyleSheets page

wysota
23rd May 2009, 12:07
Apply a stylesheet acting on objects that are children of QMessageBox on the application object.

QMessageBox QPushButton {
color: white;
}

aamer4yu
23rd May 2009, 12:10
It should be QMessageBox > QPushButton I guess :rolleyes:

QMessageBox > QPushButton {
color: white;
}

wagmare
23rd May 2009, 12:23
Also in your code, it is useless to have msgBox, since you are actually calling message box thru one of the static functions of QMessageBox.


ya ... i got the mistake ... how stupid i am declaring a msgbox and using one of the static functions of QMessageBox. .. . and setting stylesheet to msgBox

wysota
23rd May 2009, 12:41
It should be QMessageBox > QPushButton I guess

It depends if you want a direct child or any descendant widget.

aamer4yu
23rd May 2009, 12:45
RIght, I guess i read thru assistant a little fast.
By the way,, how do we insert CSS Code ?????????????

wysota
23rd May 2009, 13:26
If you're asking about the forum, then use the [highlight=css] tag.