当前位置:网站首页>Precautions for binding shortcut keys of QPushButton

Precautions for binding shortcut keys of QPushButton

2022-07-06 18:52:00 HL_ Aeolus

In a daily development , You need to add a shortcut key operation for the button , Pressing a key on the designated keyboard is equivalent to clicking this button with the mouse , This is the function of shortcut keys
There is a phenomenon that when the order of adding shortcut keys is like this , Invalid shortcut key
First bind the shortcut keys , Then set the button text , Invalid

QKeySequence keyCut(Qt::Key_Return);
btnStart->setShortcut(keyCut);
btnStart->setText(" Start ");

Set the text first , Then bind the shortcut keys , It works

btnStart->setText(" Start ");
QKeySequence keyCut(Qt::Key_Return);
btnStart->setShortcut(keyCut);

Then I try again to comment out the code that sets the text , Then bind the shortcut key , Run the program , Press enter , I rely on , The program crashed

//btnStart->setText(" Start ");
QKeySequence keyCut(Qt::Key_Return);
btnStart->setShortcut(keyCut);

The above is a small detail I found in a daily development , I don't know if it's my version Qt5.7.1 Reasons for too low , At present, I haven't tried the higher version Qt Whether there is the same phenomenon , Welcome to leave a message for discussion !!

原网站

版权声明
本文为[HL_ Aeolus]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/187/202207061101046740.html