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);
    setFont(font);
    setTextColor(Qt::white);
    QPalette pl = palette();
    pl.setColor(QPalette::Base,Qt::black);
    setPalette(pl);
    @


  • 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:
    @
    pl.setColor(QPalette::Text,Qt::white);
    @



  • 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.