qkeyevent

Get the “name” of a key from QKeyEvent in Qt

我的未来我决定 提交于 2019-12-08 16:37:31
问题 Is there an easy way of getting the name of a key (so something like "uparrow" from a key event instead of just getting the key code "16777235")? Do I have to make a list of key names myself? 回答1: Using human-readable names in your code You can use the Qt::Key enum, or get the key as a string with QKeyEvent::text(). From QKeyEvent documentation: int QKeyEvent::key () const Returns the code of the key that was pressed or released. See Qt::Key for the list of keyboard codes. These codes are

Qt sending keyPressEvent

懵懂的女人 提交于 2019-12-07 15:44:32
问题 I want to append chars to QLineEdit by sending KeyEvent. I'm using code like this: ui.myEdit->setFocus(); for(size_t i = 0; i < 10; ++i) { QKeyEvent keyPressed(QKeyEvent::KeyPress, 'a', Qt::NoModifier); QWidget::keyPressEvent(&keyPressed); // or //QApplication::sendEvent(QApplication::focusWidget(), &keyPressed); } Why there is no change in myEdit ? 回答1: You can change the change the text of QLineEdit simply by : ui->myEdit->setText(ui->myEdit->text().append("a")); But if you really want to

How to convert a Windows native virtual key code to Qt::Key?

送分小仙女□ 提交于 2019-12-07 05:32:06
问题 I am working on a program which communicates with a windows native program, so it needs the actucal native virtual key code. How to convert from a Windows native virtual key code to Qt::Key? 回答1: If you have access to a QKeyEvent , key() and nativeVirtualKey may help. From Assistant, qthelp://com.trolltech.qt.472/qdoc/qkeyevent.html#details 回答2: Look in the file qt\src\gui\kernel\qkeymapper_win.cpp 来源: https://stackoverflow.com/questions/7482213/how-to-convert-a-windows-native-virtual-key

Qt sending keyPressEvent

南楼画角 提交于 2019-12-06 01:45:11
I want to append chars to QLineEdit by sending KeyEvent. I'm using code like this: ui.myEdit->setFocus(); for(size_t i = 0; i < 10; ++i) { QKeyEvent keyPressed(QKeyEvent::KeyPress, 'a', Qt::NoModifier); QWidget::keyPressEvent(&keyPressed); // or //QApplication::sendEvent(QApplication::focusWidget(), &keyPressed); } Why there is no change in myEdit ? You can change the change the text of QLineEdit simply by : ui->myEdit->setText(ui->myEdit->text().append("a")); But if you really want to change it by sending QKeyEvent you can try this : QKeyEvent * eve1 = new QKeyEvent (QEvent::KeyPress,Qt::Key

Qt Key Pressevent Enter

戏子无情 提交于 2019-12-06 00:56:11
问题 void LoginModle::keyPressEvent(QKeyEvent *event) { qDebug() << event->key() << "\t" << Qt::Key_Enter << "\t" << QKeyEvent::Enter; if( event->key() == Qt::Key_Enter) OKButtonClicked(); else QDialog::keyPressEvent(event); } This code is very simple, class LoginModle inherits from QWidget . run this code and when I press Enter , it shows: 16777220 16777221 10 It means that my Enter in keyboard is 16777220 , but in Qt, it was defined as 16777221 . My system is Elementary OS (Freya), which is

How to convert a Windows native virtual key code to Qt::Key?

自闭症网瘾萝莉.ら 提交于 2019-12-05 09:46:03
I am working on a program which communicates with a windows native program, so it needs the actucal native virtual key code. How to convert from a Windows native virtual key code to Qt::Key? Michael Simpson If you have access to a QKeyEvent , key() and nativeVirtualKey may help. From Assistant, qthelp://com.trolltech.qt.472/qdoc/qkeyevent.html#details sat4ripe Look in the file qt\src\gui\kernel\qkeymapper_win.cpp 来源: https://stackoverflow.com/questions/7482213/how-to-convert-a-windows-native-virtual-key-code-to-qtkey

Qt Key Pressevent Enter

纵饮孤独 提交于 2019-12-04 07:29:00
void LoginModle::keyPressEvent(QKeyEvent *event) { qDebug() << event->key() << "\t" << Qt::Key_Enter << "\t" << QKeyEvent::Enter; if( event->key() == Qt::Key_Enter) OKButtonClicked(); else QDialog::keyPressEvent(event); } This code is very simple, class LoginModle inherits from QWidget . run this code and when I press Enter , it shows: 16777220 16777221 10 It means that my Enter in keyboard is 16777220 , but in Qt, it was defined as 16777221 . My system is Elementary OS (Freya), which is based on Ubuntu 14.04. Is there something wrong with my driver or just the program's mistake ? 16777220(dec

How can I disable Alt + F4 window closing using Qt?

99封情书 提交于 2019-12-02 20:53:33
I've disabled X button in Qt from my dialog using this line: myDialog->setWindowFlags(Qt::Dialog | Qt::Desktop) but I couldn't detect Alt + F4 using this code: void myClass::keyPressEvent(QKeyEvent *e) { if ((e->key()==Qt::Key_F4) && (e->modifiers()==Qt::AltModifier)) doSomething(); } what should I do to detect Alt + F4 or disable it in Qt? Pressing Alt+F4 results in a close event being sent to your top level window. In your window class, you can override closeEvent() to ignore it and prevent your application from closing. void MainWindow::closeEvent(QCloseEvent * event) { event->ignore(); }

how to accept/ignore QKeyEvent

不问归期 提交于 2019-12-02 10:11:04
问题 http://qt-project.org/doc/qt-5/qwidget.html#keyPressEvent Note that QKeyEvent starts with isAccepted() == true, so you do not need to call QKeyEvent::accept() - just do not call the base class implementation if you act upon the key. http://qt-project.org/doc/qt-5/qkeyevent.html#details A key event contains a special accept flag that indicates whether the receiver will handle the key event. You should call ignore() if the key press or release event is not handled by your widget. A key event is

Get key position of QKeyEvent (multiplatform)

风流意气都作罢 提交于 2019-12-02 08:53:31
问题 In order to make position-based keyboard shortcuts, that work for all keyboard layouts, I need to identify a physical keyboard key, without the keyboard layout on top of it. Ideally, I would like to retrieve the scancode of the QKeyEvent, because that is not keyboard layout-dependent. For example, if I would want to map Shift+Q to volume-down and Shift+W to volume-up (two keys which are next to each other on a US keyboard layout) I could just map these to Shift+0x10 and Shift+0x11 , according