Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Language Bindings
  4. Ctrl+Alt key modifier behavior with Qt on windows when a textbox has focus
Forum Updated to NodeBB v4.3 + New Features

Ctrl+Alt key modifier behavior with Qt on windows when a textbox has focus

Scheduled Pinned Locked Moved Language Bindings
2 Posts 1 Posters 4.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    elgur
    wrote on 28 Feb 2012, 22:21 last edited by
    #1

    I posted this question on SO, but I thought I'd try here too.

    I made a quick sample program to demonstrate the problem
    @
    import sys

    from  PyQt4 import QtGui
    from PyQt4.QtCore import Qt
    
    class AWindow(QtGui.QMainWindow):
        def __init__(self, parent=None):
            super(AWindow, self).__init__(parent=parent)
        
            self.setCentralWidget(QtGui.QWidget())
            self.centralWidget().setLayout(QtGui.QFormLayout())
        
            self.centralWidget().layout().addRow(
                QtGui.QLabel('some text'),
                QtGui.QLineEdit()
                )
            self.centralWidget().layout().addRow(
                QtGui.QLabel('some text'),
                QtGui.QCheckBox('this is checkbox')            
                )
    
        def keyPressEvent(self, e):
            if int(e.modifiers()) == (Qt.ControlModifier+Qt.AltModifier):
                if e.key() == Qt.Key_K:
                    #when ctrl+alt+k is pressed, a message box should open
                    msg = QtGui.QMessageBox(
                        QtGui.QMessageBox.Information,
                        'w00t',
                        'You pressed ctrl+alt+k'
                        )
                msg.exec_()
    def main():
        app = QtGui.QApplication(sys.argv)
        w = AWindow()
        w.show()
        sys.exit(app.exec_())
    
    if __name__ == '__main__':
        main()
    

    @

    The problem

    In this sample I'm capturing the ctrl+alt+k keyboard shortcut. The problem is that if a text entry widget has keyboard focused when those keys are pressed, it is not captured by the keyPressEevent handler, instead an upper case K is typed into the box. (this is the same with all ctrl+alt keypresses).

    If another kind of widget is focused, one that does not accept text input (e.g. a checkbox, button) the key press is registered as it should and in the sample, the messagebox is shown.
    Also, keyboard shortcuts that use only a Ctrl modifier work fine.

    This problem only presents it self on Windows, but not on Linux, so this leads me to believe this has something to do with how windows handles the ctrl+alt modifier, or perhaps I'm not capturing the modifiers properly.

    Is there any way to fix this?

    1 Reply Last reply
    0
    • E Offline
      E Offline
      elgur
      wrote on 28 Feb 2012, 23:54 last edited by
      #2

      For future reference, I have come up with a solution to the problem.
      See here
      http://stackoverflow.com/questions/9490453/ctrlalt-key-modifier-behavior-with-qt-on-windows-when-a-textbox-has-focus

      1 Reply Last reply
      0

      1/2

      28 Feb 2012, 22:21

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved