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] Scrolling to a particular line number in the QTextBrowser
QtWS25 Last Chance

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

Scheduled Pinned Locked Moved General and Desktop
5 Posts 3 Posters 4.9k Views
  • 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 Offline
    A Offline
    amban
    wrote on last edited by
    #1

    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
    0
    • A Offline
      A Offline
      amban
      wrote on last edited by
      #2

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

      1 Reply Last reply
      0
      • R Offline
        R Offline
        RazrFalcon
        wrote on last edited by
        #3

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

        1 Reply Last reply
        0
        • BilbonSacquetB Offline
          BilbonSacquetB Offline
          BilbonSacquet
          wrote on last edited by
          #4

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

          1 Reply Last reply
          0
          • A Offline
            A Offline
            amban
            wrote on last edited by
            #5

            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
            0

            • Login

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