Setting the cursor color

  • Hi,
    I am using the following code to format my QTextEdit , but i am not able to change color of the cursor to white.

    please let me know how to change the color of the cursor to white.

    QFont font("Arial",9,QFont::Courier,FALSE);
    QPalette pl = palette();

  • Moderators

    you mean the blinking text cursor not the mouse cursor right?
    Are you tied to using QPalette or can you also use stylesheets?

    Following should do what you want:
    myTextEdit->setStyleSheet("QTextEdit {background-color: black; color : white; }");

    but if you need to stick to QPalette you need to add the following line:

  • Thank for the reply.

    Thats working fine , there is one more problem whenever i copy paste some colored text to my QTextEdit from other page and press enter my future text in the window is also changing to same color.

    how to disable it.

  • Solved by using
    @ setTextColor(Qt::white); @
    again after pressing enter.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.