DoubleClick in TableView
-
Hey i have a TableView.
Now i want to get a Signal when i make a DoubleClick in the TableView.
Any Idea?
-
Have a look at QAbstractItemView signals
-
Yes,
but what should i write in "index" ?
void doubleClicked(const QModelIndex & index)
-
How to connect to:
connect(tableView,SIGNAL(doubleClicked(QModelIndex)),this, SLOT(doubleClickedTableView(QModelIndex)));
It's old syntax, you can use the new one of course.
Your slot method should look like this:
void Myclass::doubleClickedTableView(const QModelIndex &index) { QUrl url=index.data(Qt::ToolTipRole).toUrl(); // you retreive the data at the index (here an url) // and then emit a signal or do what ever you want if(url.isValid()) emit loadUrl(url); }
-
Yes,
but what should i write in "index" ?
void doubleClicked(const QModelIndex & index)
@notyourfan said in DoubleClick in TableView:
but what should i write in "index" ?
Nothing - it's a signal!
https://doc.qt.io/qt-5/signalsandslots.html -
This post is deleted!
-
This post is deleted!
Where should i connect this signal?
In my Model?You can call the
connect()
anywhere that the necessary variables/functions you specify are visible. So it does not have to be "inside" anything in particular, most people put connections somewhere in their start up of the UI.However, putting it inside the model code area/classes is not a good idea. Models should not need to know anything about views. OTOH, views do need to know about models, so in the view code, or in the calling code which creates the view, would be best.