2

I have a simple QPushButton on the MainWindow. I've added a slot for it:

void MainWindow::on_mybutton_pressed() {
      QString file_name = QFileDialog::getSaveFileName(
          this,
          tr("Saving File"),
          QDir::homePath(),
          "Text files (*.txt);;Any file (*.*)");
}

But when the QFileDialog is closed the QPushButton remains pressed until I press another QPushButton.

How can I fix this?

Dmitriy
  • 5,357
  • 8
  • 45
  • 57

1 Answers1

3

I found that using the slot name:

on_mybutton_clicked()

instead of

on_mybutton_pressed()

Fixes this problem.

Dmitriy
  • 5,357
  • 8
  • 45
  • 57
  • 2
    Yes, always connect to clicked() instead of pressed() to act on button clicks. (E.g. when the user moves the mouse out of the button while having the mouse button pressed and then releases the mouse button outside, one expects the button to not be triggered; pressed() would cause a click) – Frank Osterfeld Feb 07 '12 at 08:05
  • fixed this for me too on OSX. – ndbd Jul 18 '16 at 21:40