Pushbutton problem
-
I have a lineEdit next to a Save button and Cancel button. After entering text in the lineEdit, for some elusive reason, I can click the button with my mouse and it works. But, when I tab to the button and press
enter, it doesn't work.I don't use Qt enough to know why it sees a problem with me pressing
enterinstead of mouse clicking it. this is what I have:void MainWindow::on_pushButton_SaveNewName_pressed() { on_pushButton_SaveNewName_clicked(); } void MainWindow::on_pushButton_SaveNewName_clicked() { QSqlQuery q(db); if (!db.open()) { ui->statusbar->showMessage( db.lastError().text()); } else { q.exec("PRAGMA foreign_keys = 1"); q.prepare("INSERT INTO STUDIERS( STUDIER ) VALUES(" + quoteSQL(ui->lineEdit_AddNewName->text()) + ")"); if(!q.exec()) qDebug() << q.lastError().text(); } db.close(); ui->lineEdit_AddNewName->setText(""); ui->lineEdit_AddNewName->setVisible(false); ui->pushButton_SaveNewName->setVisible(false); ui->pushButton_CancelNewName->setVisible(false); ui->pushButton_AddNewName->setEnabled(true); ui->comboBox_SelectName->setEnabled(true); ui->menu_File->actions().at(0)->setEnabled( true); ui->comboBox_SelectName->clear(); loadNames(); ui->comboBox_SelectName->setFocus(); }Why won't
pressedwork?Happy Thanksgiving, everyone!
-
Hi,
From the documentation:
pressed() is emitted when the left mouse button is pressed while the mouse cursor is inside the button -
Hi,
From the documentation:
pressed() is emitted when the left mouse button is pressed while the mouse cursor is inside the button -
What you want to do is the standard behavior of QDialog (you're using a window/widget)
Have a look at QDialogButtonBox Class and QDialog examples in the Qt docs. -
Look at this link
They're talking about the space bar instead.
In the Qt doc about setDefault()
The default button behavior is provided only in dialogs. Buttons can always be clicked from the keyboard by pressing Spacebar when the button has focus.
-
Look at this link
They're talking about the space bar instead.
In the Qt doc about setDefault()
The default button behavior is provided only in dialogs. Buttons can always be clicked from the keyboard by pressing Spacebar when the button has focus.
-
@Driftwood pressed() is also called if button has focus and user presses space key (at least on my Linux).
-
@Driftwood pressed() is also called if button has focus and user presses space key (at least on my Linux).
@jsulm Exact same for me. Why the <enter> key isn't mapped for this is beyond me. I know that I can toggle radio buttons and checkboxes with the spacebar. This is true for most Gui toolkits. But when I want to use the keyboard to press button, the <enter> key makes more sense than the spacebar. I come from wxWidgets, where the <enter> key works that way.
Thanks for responding.