'Get QKeySequenceEdit value
Am having issues getting the value of my "QKeySequenceEdit", I need to get this value to print it on a label and console.
This is my code:
##Create my KeySecuenceEdit
self.ksec_hotkey = QtWidgets.QKeySequenceEdit(self.gpb_main)##it is inside of a groupbox
self.ksec_hotkey.setGeometry(QtCore.QRect(10, 75, 85, 27))
self.ksec_hotkey.setFocusPolicy(QtCore.Qt.StrongFocus)
self.ksec_hotkey.setObjectName("ksec_hotkey")
self.ksec_hotkey.keySequenceChanged.connect(self.show_ksec)##Call my function here
##function to get and print keySequenceEdit value
def show_ksec(self):
ksec_value = self.ksec_hotkey.keySequence()
#print(str(ksec_value)) ##does not work
#print(ksec_value.__dict__) ##.__dict__ or .__repr__ does not work
print(ksec_value) ##prints "<PyQt5.QtGui.QKeySequence object at 0x7f28386a5dd0>"
self.lbl_print_hotkey.setText(" : " + str(ksec_value)) ##prints "<PyQt5.QtGui.QKeySequence object at 0x7f28386a5dd0>"
My code prints: "<PyQt5.QtGui.QKeySequence object at 0x7f28386a5dd0>".
I read about issues with classes, so this is my program so far:
class Ui_MainWindow(object):
##here is my function to print
def show_ksec(self):
##here is where my qkeysequence and all my widgets are
def setupUi(self, MainWindow):
Solution 1:[1]
You have to use the toString()
method of QKeySequence
:
keysequence = self.ksec_hotkey.keySequence()
text = keysequence.toString(QKeySequence.NativeText)
# or
# text = keysequence.toString(QKeySequence.PortableText)
self.lbl_print_hotkey.setText(f" : {text}")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | eyllanesc |