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. Input in QTextEdit cause vertical scroll bar jumping
QtWS25 Last Chance

Input in QTextEdit cause vertical scroll bar jumping

Scheduled Pinned Locked Moved Unsolved General and Desktop
qtexteditinput
6 Posts 2 Posters 2.8k 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.
  • H Offline
    H Offline
    hcfalan
    wrote on 30 May 2016, 06:46 last edited by
    #1

    I have developed a small GUI program based on QT 5.4, there
    is a QTextEdit widget. The widget can paste and display
    pictures. When the displayed picture high than widget's
    height(vertical scroll bar appears), input text(and
    picture is in the same row of the cursor) will cause the
    thumb of vertical scroll bar jumping up and down, the
    experience very unfriendly! how to do?

    input 1

    input 2, now scroll bar jump up

    input 2 again, now scroll bar jump down

    keeps input, it just keeps jumping up and down, OMG!

    1 Reply Last reply
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 30 May 2016, 21:28 last edited by
      #2

      Hi,

      Just to be sure I understand you correctly, when you paste an image that is higher than the widget height and then start to type some text, the scroll bar jumps down to where the text should be ? And then if you paste a new image there, it stays at the top of the newly inserted image ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • H Offline
        H Offline
        hcfalan
        wrote on 31 May 2016, 02:14 last edited by
        #3

        After paste an image on a clean QTextEdit, it displays scroll bar and jump down to maximized value,
        so we can see the bottom part of image. Then type in one character, the scroll bar jump up to 0 value, so we can see the top part of image. Because the text is align to bottom of image, so the character just typed in is out of display area of widget.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 31 May 2016, 22:37 last edited by
          #4

          Can you share a minimal compilable example that produce this behavior ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • H Offline
            H Offline
            hcfalan
            wrote on 1 Jun 2016, 01:35 last edited by
            #5

            mainwindow.h

            #ifndef MAINWINDOW_H
            #define MAINWINDOW_H
            
            #include <QMainWindow>
            
            namespace Ui {
            class MainWindow;
            }
            
            class MainWindow : public QMainWindow
            {
                Q_OBJECT
            
            public:
                explicit MainWindow(QWidget *parent = 0);
                ~MainWindow();
            
            private slots:
                void on_actionInsert1_triggered(bool);
            private:
                Ui::MainWindow *ui;
            };
            
            #endif // MAINWINDOW_H
            
            

            mainwindow.cpp

            #include "mainwindow.h"
            #include "ui_mainwindow.h"
            #include <QTextDocumentFragment>
            
            MainWindow::MainWindow(QWidget *parent)
                : QMainWindow(parent)
                , ui(new Ui::MainWindow)
            {
                ui->setupUi(this);
            }
            
            MainWindow::~MainWindow()
            {
                delete ui;
            }
            
            void MainWindow::on_actionInsert1_triggered(bool checked)
            {
                QTextDocumentFragment fragment;
                fragment = QTextDocumentFragment::fromHtml(
                            QString("<img src='d:/ddd.png'>"));
                ui->textEdit->textCursor().insertFragment(fragment);
            }
            
            

            mainwindow.ui

            <?xml version="1.0" encoding="UTF-8"?>
            <ui version="4.0">
             <class>MainWindow</class>
             <widget class="QMainWindow" name="MainWindow">
              <property name="geometry">
               <rect>
                <x>0</x>
                <y>0</y>
                <width>800</width>
                <height>120</height>
               </rect>
              </property>
              <property name="windowTitle">
               <string>MainWindow</string>
              </property>
              <widget class="QWidget" name="centralWidget">
               <layout class="QHBoxLayout" name="horizontalLayout">
                <item>
                 <widget class="QTextEdit" name="textEdit"/>
                </item>
               </layout>
              </widget>
              <widget class="QMenuBar" name="menuBar">
               <property name="geometry">
                <rect>
                 <x>0</x>
                 <y>0</y>
                 <width>400</width>
                 <height>23</height>
                </rect>
               </property>
               <widget class="QMenu" name="menuTest">
                <property name="title">
                 <string>test</string>
                </property>
                <addaction name="actionInsert1"/>
               </widget>
               <addaction name="menuTest"/>
              </widget>
              <action name="actionInsert1">
               <property name="text">
                <string>insert 1</string>
               </property>
              </action>
              <action name="actionInsert2">
               <property name="text">
                <string>insert 2</string>
               </property>
              </action>
             </widget>
             <layoutdefault spacing="6" margin="11"/>
             <resources/>
             <connections/>
            </ui>
            
            

            Before run this example, please prepare a picture on your disk, and make sure that the height of picture more than 120 pixel, the width of picture less than 600 pixel. The picture location is hard code in MainWindow::on_actionInsert1_triggered method, please change it to your picture location and recompile.

            Run this example, first click menu item 'insert 1' to insert picture into QTextEdit widget, after pictrue displayed, you will found that the vertical scroll bar now is available. Then type in slowly one bye one, notice the scroll bar, it will jump up/down with typing.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 1 Jun 2016, 21:14 last edited by
              #6

              Looks like it might be a limitation/bug. The behavior is the same with 5.6

              You should go to the bug report system to see if it's something known. If not please consider opening a new report providing a minimal compilable example (not just the code files) to reproduce the behavior.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              5/6

              1 Jun 2016, 01:35

              • Login

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