jeudi 26 mars 2020

QTableView does not detect doubleClick

I have a QTableView and as I double click I would like to open a QInputDialog.

roslaserscandialog.h

private slots:
    void on_tableView_doubleClicked(const QModelIndex &index);

roslaserscandialog.cpp

 ROSLaserScanDialog::ROSLaserScanDialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::ROSLaserScanDialog)
{
    ui->setupUi(this);

connect(ui->tableView,SIGNAL( doubleClicked(const QModelIndex&)), this, SLOT ( on_tableView_doubleClicked(const QModelIndex &index)));

}


void ROSLaserScanDialog::on_tableView_doubleClicked(const QModelIndex &index)
{
    QString rosMsg = QInputDialog::getText(this, "ROS Msg Name", "Enter Msg");
    Q_UNUSED(index)
}

I have tried in many different ways to have the QTableView detecting my doubleclick but what I tried so far was not successful:

1) this is one of the trial I tried, that should work as I also followed official documentation:

QObject::connect(ui->tableView, SIGNAL(doubleClicked()), this, SLOT(on_tableView_doubleClicked()));

2) I tried to open it also in the following way:

QObject::connect(ui->tableView, QOverload<int>::of(&QTableView::doubleClicked),
    [=](int index) { on_tableView_doubleClicked(const QModelIndex &index); });

The error I receive from the debugger is the following below but I don't understand how that could happen:

QObject::connect: No such signal QTableView::doubleClicked() in /home/emanuele/Desktop/ultrasound_mapper/src/ERDatabaseSystem/ui/roslaserscandialog.cpp:128 QObject::connect: (sender name: 'tableView') QObject::connect: (receiver name: 'ROSLaserScanDialog')

I researched and came across this source, this other source which was useful and as the comment suggested that example was working properly. But didn't work on mine.

Another post suggested the use of this official source in particular using QAbstractItemView::doubleClicked. However I don't think I have to go down that road for this simple example and do not need to complicate the view.

This post solved the problem in the exact way I am trying to solve my problem, but I don't understand why nothing happens on my QTableView.

Please point to the right direction on how to better solve this problem.

Aucun commentaire:

Enregistrer un commentaire