PDA

View Full Version : QColorDialog background color help.



Gloplates
10th May 2017, 16:10
Hi, Hoping someone can help me out. Im pretty new to QT and developing an App to run on the Raspberry Pi.. SO far, all great, but have an issue with using the QColorDialog. In my application, my mainwindow.ui background is black, and when i open a QColorDialog, it inherits the same background color. Ive tried using a stylesheet and that doesnt work.. Ive used the QColorDialog::DOntUseNativeDialog to force the use of QT's version.

QColorDialog mycolordialog;
mycolordialog.setStyleSheet("background-color:grey");
QColor color = mycolordialog.getColor(Qt::white, this, "Effect Color", QColorDialog::DontUseNativeDialog);


Can anyone tell me why i cant change the background of the color picker to grey ?

Thanks !


Pete

d_stranz
10th May 2017, 22:03
QColorDialog::getColor() is a static member of the QColorDialog class. Even though you are calling it using a reference to an instance of a QColorDialog class (mycolordialog) it cannot use any of the properties you have set on that instance since the method is static and does not use any instance when it is called.

If you want your changes to be used, then you have to call a non-static member, such as QDialog::exec() and then retrieve the chosen color (using QColorDialog::selectedColor()) after exec() returns with an "Accepted" value.