Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] Cursor behavior in QTextEdit after applying stylesheet
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Cursor behavior in QTextEdit after applying stylesheet

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 3.2k Views 1 Watching
  • 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.
  • H Offline
    H Offline
    hryqt
    wrote on last edited by
    #1

    Dear all,

    I used FocusInEvent and FocusOutEvent to change background color of QTextEdit using stylesheet.

    If I don't change the background color, the cursor behaves correctly (appear in QTextEdit when I click it, and gone when it lost focus).

    However, when I change background color (using stylesheet), the cursor remain appear (and blinking) in QTextEdit, so that when I click different QTextEdit, the cursor will appear (and blinking) in two QTextEdit.

    I tried to set cursor width to 0 to make it disappear after QTextEdit lost focus, however I couldn't restore back the cursor. I set the width to 1 and 2, none of them work/recover the cursor.

    What should I do to solve/work around this issue?

    Thank you so much.

    1 Reply Last reply
    0
    • J Offline
      J Offline
      Jake007
      wrote on last edited by
      #2

      I did not know the solution, but I had an idea what might be wrong.

      Pass events to QTextEdit class for "further processing"

      @void TextEdit::focusInEvent(QFocusEvent *e)
      {
      setStyleSheet("background-color: #F00");

      QTextEdit::focusInEvent(e); // Notice
      }

      void TextEdit::focusOutEvent(QFocusEvent *e)
      {
      setStyleSheet("");

      QTextEdit::focusOutEvent(e); // Notice
      }
      @

      In my test project worked.

      Regards,
      Jake


      Code is poetry

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hryqt
        wrote on last edited by
        #3

        Is "TextEdit" a derived class from QTextEdit?

        I did it in different way, by overloading the eventFilter(QObject*, QEvent).

        I will try your way and I will post an update.

        Thanks a lot Jake.

        1 Reply Last reply
        0
        • J Offline
          J Offline
          Jake007
          wrote on last edited by
          #4

          Yes, TextEdit is derived from QTextEdit.

          If you used the eventFilter(), the procedure should be the same.
          Just forward the event at the end.
          @
          bool TextEdit::eventFilter(QObject *obj, QEvent *event)
          {
          // Your code

            return QTextEdit::eventFilter(obj, event);
          

          }
          @


          Code is poetry

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hryqt
            wrote on last edited by
            #5

            Hi Jake,

            I tried using eventFilter() and pass it to QTextEdit class...didn't work.

            But the solution you gave work! Overloading focusInEvent() and focusOutEvent().

            Thanks a lot Jake!

            1 Reply Last reply
            0

            • Login

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • Users
            • Groups
            • Search
            • Get Qt Extensions
            • Unsolved