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. QTextCursor::clearSelection() doesn't work
Forum Updated to NodeBB v4.3 + New Features

QTextCursor::clearSelection() doesn't work

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.7k 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.
  • S Offline
    S Offline
    ScienziatoBestia
    wrote on last edited by
    #1

    Hi to all,
    I don't wont selection in my QTextBrowser so I wrote the follow code:
    @
    MyTextBrowser::MyTextBrowser(QWidget *parent) :
    QTextBrowser(parent)
    {
    .
    .
    .
    .

    connect(this, SIGNAL(selectionChanged()), this, SLOT(clearSelection()));
    

    .
    .
    .
    }

    void MyTextBrowser::clearSelection()
    {
    textCursor().clearSelection();
    }

    @

    by debug I see that the program go inside clearSelection() but textCursor().clearSelection(); doesn't do nothing.

    Is it a bug? How can I solve?
    Thanks

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      Method textCursor() returns a copy of the text cursor. If you modify it, that changes are not automatically applied to the text edit. You have to set the the modified cursor explicitly:

      @
      void MyTextBrowser::clearSelection()
      {
          QTextCursor c = textCursor();
      c.clearSelection();
      setTextCursor(c);
      }
      @

      http://www.catb.org/~esr/faqs/smart-questions.html

      1 Reply Last reply
      0
      • S Offline
        S Offline
        ScienziatoBestia
        wrote on last edited by
        #3

        thank you...
        I was simply stupid

        1 Reply Last reply
        0
        • G Offline
          G Offline
          goetz
          wrote on last edited by
          #4

          [quote author="ScienziatoBestia" date="1309505105"]thank you...
          I was simply stupid
          [/quote]

          No problem, long time ago I stepped into that trap too :-)

          http://www.catb.org/~esr/faqs/smart-questions.html

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jim_kaiser
            wrote on last edited by
            #5

            Just to clarify, you could modify the text document with something like

            @
            QTextCursor cursor = textEdit->textCursor();
            cursor.insertText("blahblah");
            @

            without needing to call setTextCursor().

            But the selection itself is a property of the text cursor and only on setTextCursor() is the visual cursor updated and hence the selection.

            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