[Solved]Change text cursor color in QTextEdit
-
wrote on 21 Oct 2012, 21:44 last edited by
Hello,
I need to have black background color and white text in a text editor. I have achieved this, but I cannot find a way to change the text cursor color to white and therefore the black cursor is invisible.
Is there a way to do this?.
-
wrote on 31 Oct 2012, 07:36 last edited by
If the Text Color is White in color then obviously the Text Cursor Color will also be White in color. You need to change the Text Cursor Color alone to Black, keeping the Text Color in White itself ? Please be clear with that.
-
wrote on 31 Oct 2012, 08:07 last edited by
yes, i think that if change the text color, then the text cursor obviously should change color too. But that doesn't happen.
so I have black background, and I have changed the text color to white, BUT the cursor color doesn't change to the same color as the text and is therefore invisible. Which is why asked if it is explictly possible to change the cursor color.
to clarify, here is my desired setup:
black background, white text, white cursor.and what actually happens after changing the colors:
black background, white text, black cursor. -
wrote on 31 Oct 2012, 08:24 last edited by
Did u tried to change the Stylesheet by using Ui Designer or by Coding ? I Tried it in Designer and it Works Fine for me...
Thanks & Regards
-
wrote on 31 Oct 2012, 08:36 last edited by
I will update the screen shot of my output for your reference..
-
wrote on 31 Oct 2012, 08:47 last edited by
!http://img546.imageshack.us/img546/296/mainwindowr.png(Text Edit with White Color and Text Cursor with White Color )!
-
wrote on 31 Oct 2012, 08:57 last edited by
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.
-
wrote on 31 Oct 2012, 12:17 last edited by
use style sheet as Riz proposed
@
QTextEdit
{
color: white;
background-color: black;
}
@ -
wrote on 31 Oct 2012, 12:28 last edited by
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. -
wrote on 31 Oct 2012, 12:32 last edited by
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();
}
@ -
wrote on 31 Oct 2012, 12:48 last edited by
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.
-
wrote on 31 Oct 2012, 13:09 last edited by
Yeah Aleksey0k is Right...!!! We can change the StyleSheet at Runtime too....
-
wrote on 31 Oct 2012, 13:22 last edited by
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..
-
wrote on 31 Oct 2012, 13:26 last edited by
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...