UI: ProgramEditDialog: Handle default button

This commit is contained in:
Nodir Temirkhodjaev 2024-02-01 20:34:52 +03:00
parent 3733819936
commit f08af8834b
3 changed files with 16 additions and 5 deletions

View File

@ -589,6 +589,7 @@ QLayout *ProgramEditDialog::setupButtonsLayout()
{
setupAdvancedMode();
// OK
m_btOk = ControlUtil::createButton(QString(), [&] {
if (save()) {
closeOnSave();
@ -596,6 +597,9 @@ QLayout *ProgramEditDialog::setupButtonsLayout()
});
m_btOk->setDefault(true);
connect(this, &WidgetWindow::defaultButtonPressed, m_btOk, &QAbstractButton::click);
// Cancel
m_btCancel = new QPushButton();
connect(m_btCancel, &QAbstractButton::clicked, this, &QWidget::close);

View File

@ -91,12 +91,17 @@ void WidgetWindow::keyPressEvent(QKeyEvent *event)
{
QWidget::keyPressEvent(event);
if (event->modifiers() != Qt::NoModifier)
return;
switch (event->key()) {
case Qt::Key_Escape:
if (event->modifiers() == Qt::NoModifier) {
case Qt::Key_Return:
case Qt::Key_Enter: {
emit defaultButtonPressed();
} break;
case Qt::Key_Escape: {
close();
}
break;
} break;
}
}

View File

@ -35,6 +35,8 @@ signals:
void aboutToShow();
void aboutToClose(QEvent *event);
void defaultButtonPressed();
protected:
void moveEvent(QMoveEvent *event) override;
void resizeEvent(QResizeEvent *event) override;