Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-3495

QTextDocument::contentsChange singal does not gives correct value.

    XMLWordPrintable

Details

    Description

      When pasting some words (say "add") at the 0 position of an existing line in a document, signal contentsChange() shows incorrect value for second and third parameter (charsRemoved, charsAdded).

      To reproduce this Run the following code:

      Type: add rest
      select "add" without space and cut
      now past at 0 position
      you will see out put: Position= 0 Chars Removed 6 Chars Added 9

      #include <QtGui>
      class MainWindow : public QMainWindow
      {
          Q_OBJECT
      public:
          MainWindow(QWidget *parent = 0)
          {
              setWindowTitle("Tesxt contentChange Signal");
              QTextEdit * textEdit = new QTextEdit;
              setCentralWidget(textEdit);       
              connect(textEdit->document(), SIGNAL(contentsChange(int,int,int)),
                  this, SLOT(myContentsChangeFunction(int,int,int)));
          }
      private:
          public slots:
              void myContentsChangeFunction(int a,int b,int c)
              {
                 qDebug()<<"Position="<<a<<"Chars Removed"<<b<<"Chars Added"<<c;
              }
      };
      
      #include "main.moc"
      int main(int argc, char *argv[])
      {
          QApplication app(argc, argv);
          MainWindow mainWindow;
          mainWindow.show();
          return app.exec();
      }
      

      Another side-effect of this problem is that when you paste text at 0 position then undo(), the cursor is returned to position (1,0) and not (0,0) as it should be. This can be reproduced with TextEdit demo of Qt4.4.3. To reproduce follow these steps.

      • Run the TextEdit demo in 4.4.3
      • Change first title line that says "QTextEdit" to align all the way
        to the left.
      • Place cursor on first position on first line.
      • Paste some text before the word "QTextEdit".
      • Now, select undo.
      • Cursor should have been placed back at position 0,0.
      • But it is not, it is placed at the beginning of the next line

      These are reproducible with Qt4.4 on Vista.

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              esabraha Eskil Abrahamsen Blomfeldt
              smk smk
              Votes:
              3 Vote for this issue
              Watchers:
              8 Start watching this issue

              Dates

                Created:
                Updated:

                Gerrit Reviews

                  There are no open Gerrit changes