PDA

View Full Version : QColorDialog problem



alenn.masic
10th November 2012, 23:03
Hi all

I have one button and textEdit and when user press that button, ColorDialog should appear and using stylesheet selected color should apply to all text in textEdit. I made the following code:


QColor color = QColorDialog::getColor(Qt::black, this);

edit->setStyleSheet(color.name()); (edit is QTextEdit)

but it's not working, ColorDialog appears, and I select color, but text in textEdit remains as it is. Can someone help me with this.

ChrisW67
11th November 2012, 05:47
The QString returned by QColor::name() is not a valid style sheet. You want something like:


edit->setStyleSheet(QString("QTextEdit { color: %1; }").arg(color.name()));

or you can use the QColor directly on the widget's palette.


QPalette pal = edit->palette();
pal.setBrush(QPalette::Text, color);
edit->setPalette(pal);

alenn.masic
11th November 2012, 09:17
thank you, it's working now