qshortcut

PySide2 | Finding out which QKeySequence was pressed 2

自闭症网瘾萝莉.ら 提交于 2019-12-24 10:25:03
问题 I had a previous question about QKeySequence here. It worked but when I applied it to my code there seemed to be an error when the QKeySequence comes after line when the button click event goes before the QKeySequence line. Note: The GUI consists of only two buttons: self.btnDSR and self.btnOther. Taking from the answer of eyllanesc in the previous question, my code follows: class MainWindow(QtWidgets.QMainWindow, test_mainWindow.Ui_MainWindow): def __init__(self, parent=None): super

PySide2 | Finding out which QKeySequence was pressed

时光毁灭记忆、已成空白 提交于 2019-12-11 04:48:42
问题 I'm using PySide2 and I want to have multiple shortcuts that carry out the same function but also would depend on which key was pressed. I tried to link the functions as such inside a QMainWindow: QtWidgets.QShortcut(QtGui.QKeySequence("1"),self).activated.connect(self.test_func) QtWidgets.QShortcut(QtGui.QKeySequence("2"),self).activated.connect(self.test_func) Such that they both execute this function. def test_func(self, signal): print(signal) Hoping that print("1") happens when the key "1

How do I make a shortcut using arrow key with PySide2?

风流意气都作罢 提交于 2019-12-10 18:50:59
问题 I want to add a keyboard shortcut to a button with Qt5 + Python (Pyside2). Code for making a shortcut with a regular key: import sys import random from PySide2 import QtCore, QtWidgets, QtGui class MyWidget(QtWidgets.QWidget): def __init__(self): super().__init__() self.hello = ["Hallo Welt", "你好,世界", "Hei maailma",\ "Hola Mundo", "Привет мир"] self.button = QtWidgets.QPushButton("Click me!") self.text = QtWidgets.QLabel("Hello World") self.text.setAlignment(QtCore.Qt.AlignCenter) self.text