Can't input non-English characters!!



  • Hi All,

    I'm testing the following code on Windows but can't understand why the QLineEdit doesn't accept non-English characters input.
    Any ideas?

    from PyQt5.QtCore import Qt, QEvent, QRegExp
    from PyQt5.QtWidgets import QTabBar, QTabWidget, QApplication, QLineEdit, QWidget
    from PyQt5.QtGui import QRegExpValidator
    
    class EditableTabBar(QTabBar):
        def __init__(self, parent):
            QTabBar.__init__(self, parent)
            self._editor = QLineEdit(self)
            self._editor.setWindowFlags(Qt.Popup)
            self._editor.setFocusProxy(self)
            self._editor.editingFinished.connect(self.handleEditingFinished)
            self._editor.installEventFilter(self)
    
        def eventFilter(self, widget, event):
            if ((event.type() == QEvent.MouseButtonPress and not self._editor.geometry().contains(event.globalPos())) or (event.type() == QEvent.KeyPress and event.key() == Qt.Key_Escape)):
                self._editor.hide()
                return True
            return QTabBar.eventFilter(self, widget, event)
    
        def mouseDoubleClickEvent(self, event):
            index = self.tabAt(event.pos())
            if index >= 0:
                self.editTab(index)
    
        def editTab(self, index):
            rect = self.tabRect(index)
            self._editor.setFixedSize(rect.size())
            self._editor.move(self.parent().mapToGlobal(rect.topLeft()))
            self._editor.setText(self.tabText(index))
            if not self._editor.isVisible():
                self._editor.show()
    
        def handleEditingFinished(self):
            index = self.currentIndex()
            if index >= 0:
                self._editor.hide()
                self.setTabText(index, self._editor.text())
    
    class Window(QTabWidget):
        def __init__(self):
            QTabWidget.__init__(self)
            self.setTabBar(EditableTabBar(self))
            self.addTab(QWidget(self), 'Tab One')
            self.addTab(QWidget(self), 'Tab Two')
    
    if __name__ == '__main__':
    
        import sys
        app = QApplication(sys.argv)
        window = Window()
        window.show()
        sys.exit(app.exec_())
    

    Thanks in advance for your help!

    Regards,
    Sat


  • Lifetime Qt Champion

    Hi,

    What are your system specification ?
    What version of PyQt ?
    What version of Qt ?
    Can you reproduce that with a simple QLineEdit ?



  • @SGaist pyqt5.9.1 on windows7. Interrstingly simple qlineedit works on a simplified widget in different app.
    I found copy&paste works but key-in not.
    Not sure if there is a configuration controlling the behavior...



  • Since QLineEdit works alone on my env, it may be a QTabBar issue???
    But until editingFinished singnal fired from QLineEdit , QLineEdit should be responsible for that, right?
    Still investigating what's going on, but have no idea for now. :<

    Sat


  • Lifetime Qt Champion

    What if you remove the event filter ?



  • @SGaist No change. :<


  • Lifetime Qt Champion

    Can you show an example of non-ascii char that fails ?

    Just tested with àüè and such and it worked fine but on macOS.



  • @SGaist Actually, it doesn't fail, just nothing happened when I key in Japanese characters such as あいうえお. Since I can copy&paste the problematic characters, it may be an environment issue(eg. Windows)??

    Thanks,
    Sat


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.