Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    [SOLVED] Scrolling to a particular line number in the QTextBrowser

    General and Desktop
    3
    5
    4470
    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.
    • A
      amban last edited by

      Hi,
      Currently I have this code which goes to a particular line number and makes the text bold. What i want to achieve is that when the QTextBrowser is invoked, it will open to last position of the cursor below and not the start of the QTextBrowser(as default).

      Please help.

      @
      QTextDocument *document = my_browser->document();
      QTextCursor cursor(document);

      for(int i=0; i<20 ; i++)
      {
      cursor.movePosition(QTextCursor::Down);
      }
      cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
      
      QTextCharFormat format;
      format.setFontWeight(QFont::Bold);
      
      cursor.mergeCharFormat(format);
      

      @

      1 Reply Last reply Reply Quote 0
      • A
        amban last edited by

        No replies...Someone please suggest me how to go about...

        1 Reply Last reply Reply Quote 0
        • R
          RazrFalcon last edited by

          You can set position manually:
          @cursor.movePosition(QTextCursor::Start);@

          1 Reply Last reply Reply Quote 0
          • BilbonSacquet
            BilbonSacquet last edited by

            You could use as alternative the select function of the QTextCursor:
            @
            cursor.select(QTextCursor::LineUnderCursor);
            cursor.mergeCharFormat(format);
            @

            1 Reply Last reply Reply Quote 0
            • A
              amban last edited by

              http://stackoverflow.com/questions/3547185/scroll-qtextbrowser-to-the-top
              This helped me. Thank you to everyone who tried to help me. I appreciate it.

              @
              QTextDocument *document = my_browser->document();
              QTextCursor cursor(document);

              for(int i=0; i<line_number-1 ; i++)
              {
              cursor.movePosition(QTextCursor::Down);
              }
              cursor.movePosition(QTextCursor::EndOfLine, QTextCursor::KeepAnchor);
              
              my_browser->setTextCursor(cursor);
              mainLayout->addWidget(my_browser);
              setLayout(mainLayout);
              

              @

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