PDA

View Full Version : QColorDialog



BrainFreeze
6th March 2011, 00:51
I was experimenting with the QColorDialog, and it works, but when I selected "Named Colors" in the comboBox that's in the dialog, I get a segmentation fault. All the other selections are fine. The color dialog looks different that the Qt4 doc I found, this isn't even in the picture of the dialog it shows. I'm using Qt4.6. What is this "Named Colors" selection, and how do I use it (or disable it)?

(I was just trying to get the #rrggbb string, and it does work, except for the above problem.)


QColor color = QColorDialog::getColor(Qt::black, this);
if(color.isValid())
{
textColorName = color.name();
QMessageBox::information(this, "Text Color", "You selected "+textColorName);
}

norobro
6th March 2011, 03:10
I get a segfault also. It seems to be a problem with the KDE native dialog. On my machine the dialog looks like the pic in the docs in Gnome and if QColorDialog::DontUseNativeDialog is set in KDE.

Can't help with the "Named Colors":).

BrainFreeze
6th March 2011, 04:16
Ok, that works! It took me a while to figure out how to write to proper code, but here's what I did to get it working:



void MainWindow::onColor()
{
QColor color = QColorDialog::getColor(Qt::black, this, "Text Color", QColorDialog::DontUseNativeDialog);
if(color.isValid())
{
textColorName = color.name();
QMessageBox::information(this, "Text Color", "You selected "+textColorName);
}
}


Thanks for your help!

norobro
6th March 2011, 04:45
Hover your mouse over the icons above the text box. For example the left "#" is for code tags.