PDA

View Full Version : QVariant::QVariant(Qt::GlobalColor)' is private



alenn.masic
21st February 2013, 15:00
declaration in header file


QColor dialogBoja, dialogBoja1;

.cpp file

dialogBoja = postavke.value("boja", Qt::black).toString();
//postavke means settings
dialogBoja1 = postavke.value("boja1", Qt::white).toString();

As I said on title, when I try to compile this in Qt5 I get error: QVariant::QVariant(Qt::GlobalColor)' is private

How to solve this.

Lykurg
21st February 2013, 15:24
Use
QVariant(Qt::black)

EDIT: But your code will even with this not compile since you are trying to set a QString on a QColor...

alenn.masic
21st February 2013, 15:38
Use
QVariant(Qt::black)

EDIT: But your code will even with this not compile since you are trying to set a QString on a QColor...

This code only saves current color in settings file.

Is this what you mean? dialogBoja = postavke.value("boja", QVariant(Qt::black)).toString();

Lykurg
21st February 2013, 15:53
Yes, but you can store QColor direct to QSetting without transforming it to a string.

alenn.masic
21st February 2013, 17:06
Yes I know, but I need it this way. I get the same error like before.

d_stranz
21st February 2013, 17:15
Why are you trying to set a QColor by converting a QSettings value to a QString? It looks like all you want is to set a default color if the QSettings does not contain an entry for your query. So do this:



dialogBoja = postavke.value("boja", QColor( Qt::black ) ).value<QColor>();

alenn.masic
21st February 2013, 17:25
Thanks, it's working after adding QColor(Qt::black). But let me explain you why I convert it to string:

dialogBoja = QColorDialog::getColor(Qt::black, this);
edit->setStyleSheet(QString("color:%1").arg(dialogBoja.name()));

That's how I use this color, maybe it's wrong but that's how I made it and I don't want to change 1600 line of code :))

Thanks for your help.

d_stranz
22nd February 2013, 16:29
So next time, abstract this to something more easily changed, like:



void setWidgetStyleSheetColor( QWidget * w, const QColor & c )
{
w->setStyleSheet(QString("color:%1").arg(c.name()));
}


and use that method call instead of your 1600 lines of hard-coding. If you find a better way of doing it, you have only one line to change.

By the way, I don't think that setting the color by name as you are doing has any effect on the string returned by the name() method. The name() method will take whatever RGBA value the internal representation is holding and turn it into a #RRGGBB string. It also looks like the name() methods strips off any alpha channel, so that will have undesirable consequences for your style sheet if you decide to use semi-transparent colors.