QTableView: How can I get the data when user click on a particular cell using mouse

你说的曾经没有我的故事 提交于 2019-12-09 15:53:57

问题


Actually I am new to Qt and unable to match up QMouseEvent with QTableview

please help in solving this issue.


回答1:


Here is an example of how you can get a table cell's text when clicking on it.

Suppose a QTableView defined in some MyClass class. You need to connect the clicked signal to your own MyClass::onTableClicked() slot, as shown below:

connect(tableView, SIGNAL(clicked(const QModelIndex &)), this, SLOT(onTableClicked(const QModelIndex &)));

Slot implementation:

void MyClass::onTableClicked(const QModelIndex &index)
{
    if (index.isValid()) {
        QString cellText = index.data().toString();        
    }
}

You can use also doubleClicked, pressed or other signals depending on your goal.



来源:https://stackoverflow.com/questions/19442050/qtableview-how-can-i-get-the-data-when-user-click-on-a-particular-cell-using-mo

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!