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] QTextEdit auto scroll source code
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] QTextEdit auto scroll source code

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k 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.
  • F Offline
    F Offline
    frankiefrank
    wrote on last edited by
    #1

    I'm implementing a subclass of QTextEdit and I need some functionality very close to the auto-scrolling which the widget already has. This is implemented in the QTextEdit.cpp source code, using a timer started when mouse is moving and stopped when it is released, emitting scroll requests on timerEvent().

    But looking at the code, there is a part I don't understand - and maybe someone familiar with widget code can help explain.

    This appears within the timerEvent() code:
    @
    const QPoint globalPos = QCursor::pos();
    pos = d->viewport->mapFromGlobal(globalPos);
    QMouseEvent ev(QEvent::MouseMove, pos, mapTo(topLevelWidget(), pos), globalPos, Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
    mouseMoveEvent(&ev);
    @

    What does this part do? Why is a mouse move event created and simulated here?

    "Roads? Where we're going, we don't need roads."

    1 Reply Last reply
    0
    • Chris KawaC Offline
      Chris KawaC Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Notice that timerEvent doesn't contain any code to stop the timer.

      The code you posted creates a mouse move event for the QTextEdit even outside of the widget. This can happen if you start to select the text and go outside the boundaries of the widget. It keeps selecting and scrolling.

      The called mouseMoveEvent in turn checks if the cursor is back in the viewport of the widget and if so it stops the timer (and thus scrolling).

      1 Reply Last reply
      0
      • F Offline
        F Offline
        frankiefrank
        wrote on last edited by
        #3

        Thank you very much for you quick reply Chris. That makes sense.

        There is some code following this extract that adjusts the timeout of the timer but I understand now that in the case you describe the delta would also be 0 so the start() line of the timer wouldn't be called.

        "Roads? Where we're going, we don't need roads."

        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