Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-1129

QTextCursor.MovePosition() returns incorrect value (always returns False )

    XMLWordPrintable

Details

    • Bug
    • Resolution: Invalid
    • Not Evaluated
    • None
    • 5.13.1
    • PySide
    • None
    • Ubuntu 17.0 running Unity
    • Linux/X11

    Description

      Issue Summary:

      Pyside2 QTextCursor.MovePosition always returns False even when condition is satisfied and function should return True

      This behavior is different from behavior of the same code written in C++ using Qt 5.7.1

      Steps To Reproduce:

      1. Inherit CustomTextEdit from QPlainTextEdit and re-implement the keyPressEvent.
      2. in KeyPressEvent check behavior of self.cursor.movePosition(QtGui.QTextCursor.Down)

       

      class CustomTextEdit(QtWidgets.QPlainTextEdit):
          def keyPressEvent(self, event):
              QtWidgets.QPlainTextEdit.keyPressEvent(self, event)
              if event == QtGui.QKeySequence.MoveToNextLine:
                  print(self.cursor.movePosition(QtGui.QTextCursor.Down))
          def __init__(self, parent = None):
              QtWidgets.QPlainTextEdit.__init__(self, parent)
              self.main_window = parent
              self.cursor = QtGui.QTextCursor(self.document())
              self.setTextCursor(self.cursor)
      

       

       

      Result:

      This code strng  returns False in all conditions. 

      Expected Result

      It should return  True if cursor has been moved down (to the next text line) and return False if the cursor can not be moved to the next line (say it is positioned on the last line of text in QPlainTextEdit Widget.

      Regression

      The similar code written in C++ Qt version 5.7.1  returns "1" when QTextCursor.movePosition() can be executed successfully  and returns "0" when the cursor is unable to move.

      class CustomTextEdit : public QPlainTextEdit
      {
      public:
          //QTextCursor textCursor();
      
      protected:
          virtual void keyPressEvent(QKeyEvent *event) Q_DECL_OVERRIDE;
      };
      
      
      void CustomTextEdit::keyPressEvent(QKeyEvent *event)
      
      {
       QPlainTextEdit::keyPressEvent(event);
      
       if(event == QKeySequence::MoveToNextLine) {
           QTextCursor cursor(textCursor());
           setTextCursor(cursor);
           cout<< cursor.movePosition(QTextCursor::Down)<<endl;
       }
      
      }

      Notes

      I am attaching test code on both python and C++. For me both files can be executed without issues. C++ file has been created with Qt Creator 4.1.0 installed from the Ubuntu 17.04 Repository.  

      Both of  these programs returns value of the cursor.movePosition(QTextCursor::Down) to the console. 

      For the C++ version you need to enter a couple of text strings, move cursor up and down  and check the value in the CLI output 

      I am also attaching CLI output for both programs for your reference.

       

      Update:

      The issue si also reproducible in PyQt5

      Attachments

        1. cppcode_output.txt
          0.6 kB
        2. cursortest.py
          2 kB
        3. main.cpp
          0.2 kB
        4. mainwindow.cpp
          0.5 kB
        5. mainwindow.h
          0.5 kB
        6. man.txt
          4 kB
        7. pyside1129.py
          1 kB
        8. pythoncode_output.txt
          0.5 kB
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            crmaurei Cristian Maureira-Fredes
            nastya_medvedeva nastya_medvedeva
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes