qkeyevent

How to call defined slots from keypress event in qt / How to connect keypressed event with QPushbutton on gui?

冷暖自知 提交于 2021-02-11 04:56:43
问题 I am beginner to qt. I was working on calculator gui application, I have already defined slots like numPressed() when any of the number pushbutton is pressed on the calculator that will be displayed on the lineEdit. void Calculator::numPressed(){ QPushButton *button = (QPushButton *)sender(); QString buttonValue = button->text(); Qstring display = ui->lineEdit->text(); Qdouble ProcessedValue = previousValue + buttonValue.toDouble(); . . . ui->lineEdit->setText(QString::number(ProcessedValue))

How to call defined slots from keypress event in qt / How to connect keypressed event with QPushbutton on gui?

情到浓时终转凉″ 提交于 2021-02-11 04:53:04
问题 I am beginner to qt. I was working on calculator gui application, I have already defined slots like numPressed() when any of the number pushbutton is pressed on the calculator that will be displayed on the lineEdit. void Calculator::numPressed(){ QPushButton *button = (QPushButton *)sender(); QString buttonValue = button->text(); Qstring display = ui->lineEdit->text(); Qdouble ProcessedValue = previousValue + buttonValue.toDouble(); . . . ui->lineEdit->setText(QString::number(ProcessedValue))

How to call defined slots from keypress event in qt / How to connect keypressed event with QPushbutton on gui?

折月煮酒 提交于 2021-02-11 04:52:57
问题 I am beginner to qt. I was working on calculator gui application, I have already defined slots like numPressed() when any of the number pushbutton is pressed on the calculator that will be displayed on the lineEdit. void Calculator::numPressed(){ QPushButton *button = (QPushButton *)sender(); QString buttonValue = button->text(); Qstring display = ui->lineEdit->text(); Qdouble ProcessedValue = previousValue + buttonValue.toDouble(); . . . ui->lineEdit->setText(QString::number(ProcessedValue))

How to call qt keyPressEvent(QKeyEvent *event) from qml Keys.onPressed

别说谁变了你拦得住时间么 提交于 2021-01-04 05:58:46
问题 I have a qml Window with an Item which has Keys.onPressed { } And I have a c++ class which has protected: void keyPressEvent(QKeyEvent *event); What needs to go inside the Keys.onPressed? I have tried myclass.keyPressEvent(event) and I have tried a public Q_INVOKABLE function (handleKeyPress) in my c++ class with parameter (QKeyEvent * event) from which I wanted to call the keyPressEvent . At runtime the former gives "TypeError: Property 'keyPressEvent' of object myclass is not a function"

Qt widget does not receive keyPressEvent

荒凉一梦 提交于 2020-03-05 07:02:15
问题 My child widget does not get keyPressEvents, while if I put the same widget as top level window, it does. I try to set it get focus, but it has no effect on this. Code is below, showing what I try to get to work. #include <QApplication> #include <QKeyEvent> #include <QLCDNumber> #include <QLabel> #include <QVBoxLayout> class DigitSummer: public QLCDNumber { Q_OBJECT public: DigitSummer(QWidget *parent = nullptr) : QLCDNumber(parent) { } protected: void keyPressEvent(QKeyEvent *event) override

Qt widget does not receive keyPressEvent

▼魔方 西西 提交于 2020-03-05 07:01:52
问题 My child widget does not get keyPressEvents, while if I put the same widget as top level window, it does. I try to set it get focus, but it has no effect on this. Code is below, showing what I try to get to work. #include <QApplication> #include <QKeyEvent> #include <QLCDNumber> #include <QLabel> #include <QVBoxLayout> class DigitSummer: public QLCDNumber { Q_OBJECT public: DigitSummer(QWidget *parent = nullptr) : QLCDNumber(parent) { } protected: void keyPressEvent(QKeyEvent *event) override

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

你离开我真会死。 提交于 2020-01-30 18:53:27
问题 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? 回答1: 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

Handle arrow key events by setting the focus policy

懵懂的女人 提交于 2020-01-14 04:43:06
问题 I want to handle key events of the arrow keys in my application. I have already read that for doing so the focus must be disabled. I follow this method: PyQt not recognizing arrow keys. Indeed, when calling self.setChildrenFocusPolicy(QtCore.Qt.NoFocus) (as defined in the linked thread and in my source code below) within MyApp.__init__ , hitting an arrow key raises a key event. However, I do not want to keep the focus disabled during the entire runtime of the application but only upon

get shift+numerical keys in qt using qkeyevent

两盒软妹~` 提交于 2019-12-12 05:39:06
问题 I am using QKeyEvent to get the Shift+numeric key, but it return me the ascii for "!" instead of "1" so my problem is, is there any method or techniques to get the actual numeric value's ascii instead of ascii of "!" (special character). I also followed this thread: Get key char (value) from keycode with shift modifier but it does not seems to help me to get rid from this problem. Thanks in advance. 回答1: I believe at least as of version 4.8 there is no standard method to get the numeric ascii