Unsolved How to catch mouse click in QDoubleSpinbox
-
Hello I have a QDoubleSpinbox and I want to make it so that when a user clicks its value, it automatically selects the value so the user can type a new value to it.
I used the following event filter. But during my test, the function is only called when I click on the main framework (anywhere outside those spinboxes). What should I do?
bool MainWindow::eventFilter(QObject* obj, QEvent* event) { if (event->type() == QEvent::MouseButtonPress){ if (obj == ui->input){ ui->input->selectAll(); return true; } if (obj == ui->error){ ui->error->selectAll(); return true; } } return QObject::eventFilter(obj, event); }
-
@MasterBlade
I don't know, but would it work if you sub-classed theQDoubleSpinbox
and overrode itseventFilter()
instead? You can have aneventFilter()
on everyQWidget
(and then it is self-contained/standalone, does not rely on writing it in container), you don't have to have it on just yourQMainWindow
or whatever. -
Hi,
You likely want to apply that to the QLineEdit used in the QDoubleSpinBox. See the lineEdit method to get it.