Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    Setting the cursor color

    General and Desktop
    2
    4
    2221
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • D
      Dcqt last edited by

      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);
      @

      1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators last edited by

        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);
        @

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        1 Reply Last reply Reply Quote 0
        • D
          Dcqt last edited by

          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.

          1 Reply Last reply Reply Quote 0
          • D
            Dcqt last edited by

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

            1 Reply Last reply Reply Quote 0
            • First post
              Last post