Details
-
Bug
-
Resolution: Invalid
-
Not Evaluated
-
None
-
5.13.1
-
None
-
Ubuntu 17.0 running Unity
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:
- Inherit CustomTextEdit from QPlainTextEdit and re-implement the keyPressEvent.
- 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