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

后端 未结 1 1316
别跟我提以往
别跟我提以往 2021-02-07 14:40

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

please help in solving this issue.

相关标签:
1条回答
  • 2021-02-07 15:04

    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.

    0 讨论(0)
提交回复
热议问题