PyQt or PySide: QTextEdit deselect all

前端 未结 2 1972
自闭症患者
自闭症患者 2021-01-13 16:57

I\'m using PySide(PyQt is fine as well) and I want to deselect everything inside a QTextEdit. Selecting everything is very easy and it\'s done by self.textedit.selectAll(),

相关标签:
2条回答
  • 2021-01-13 17:42

    You want to first get the QTextCursor for the QTextEdit

    my_text_cursor = my_text_edit.textCursor()
    

    Then clear the selection of the QTextCursor

    my_text_cursor.clearSelection()
    

    Then update the QLineEdit with the new QTextCursor (see documentation for QTextEdit.textCursor() which indicates updating the returned QTextCursor does not actually affect the QTextEdit unless you also call the following)

    my_text_edit.setTextCursor(my_text_cursor)
    
    0 讨论(0)
  • 2021-01-13 17:47

    It same too, isn't it?

    QLineEdit.deselect (self) Text all in your object.

    Example;

    .
    myQLineEdit = QLineEdit()
    .
    .
    myQLineEdit .selectAll()
    .
    .
    myQLineEdit.deselect()
    .
    

    Reference : http://pyqt.sourceforge.net/Docs/PyQt4/qlineedit.html#deselect


    Or, did your want to deselect all QLineEdit, your just find Children is a QLineEdit and deselect it all;

    myQWidget= QWidget()
    .
    .
    listsMyQLineEdit = myQWidget.findChildren(QLineEdit)
    for myQLineEdit in listsMyQLineEdit:
        myQLineEdit.deselect()
    .
    .
    

    Regards,

    0 讨论(0)
提交回复
热议问题