[Solved]Change text cursor color in QTextEdit
-
I will update the screen shot of my output for your reference..
-
!http://img546.imageshack.us/img546/296/mainwindowr.png(Text Edit with White Color and Text Cursor with White Color )!
-
I used coding, modified the demo called textedit.
I will update the code I used for color change and so on when I get back home.
-
use style sheet as Riz proposed
@
QTextEdit
{
color: white;
background-color: black;
}
@ -
Here is the code I used to change the colors:
@QPalette p = textEdit->palette();
p.setColor(QPalette::Base, QColor(0, 0, 0));
textEdit->setPalette(p);textEdit->setFrameShape(QFrame::NoFrame);
textEdit->setTextColor(QColor(255,255,255));
@
If I use a style sheet, is it possible to change the colors on the run too? The background color won't change but text color might. -
Yes, you can change style sheet at runtime:
@
QFile file("style.css");
if(file.open(QFile::ReadOnly))
{
QString styleSheet(file.readAll());
widget->setStyleSheet(styleSheet);
file.close();
}
@ -
Thanks Riz and Aleksey, it works now, using this
@
textEdit->setStyleSheet(
"QTextEdit"
"{"
"color: white;"
"background-color: black;"
"}"
);@So the cursor color can be set by setting color: whatever in a stylesheet.. But apparently not with setTextColor() or any other function of textEdit.. weird, but I'm glad it works now.
-
Yeah Aleksey0k is Right...!!! We can change the StyleSheet at Runtime too....
-
Your Welcome.. Happy Coding... :) Simple way of coding is..
@TextEdit->setStyleSheet("background-color: black; color : white");@
Thats all.... No Need for going for a QPalette and all..
-
If you are using setTextColor(),
@TextEdit->setTextColor(Qt::white);@
will change the Text Color Alone. But the Text Cursor will remain the default Black in color...