I cannot to handle double click event. I try to do this using following code
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
protected slots:
void OnDc(const QModelIndex&);
private:
Ui::MainWindow *ui;
};
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(this, SIGNAL(doubleClicked(const QModelIndex& )), this, SLOT(OnDc(const QModelIndex&)));
}
void MainWindow::OnDc(const QModelIndex&)
{
...
}
OnDc is not calling when double click happens. What did I do wrong?
You should use void QWidget::mouseDoubleClickEvent ( QMouseEvent * event ) [virtual protected]
You can override QMainWindow::mouseDoubleClickEvent
void MainWindow::mouseDoubleClickEvent( QMouseEvent * e )
{
if ( e->button() == Qt::LeftButton )
{
...
}
// You may have to call the parent's method for other cases
QMainWindow::mouseDoubleClickEvent( e );
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With