Handling single click and double click separately in QTableWidget

前端 未结 1 1899
忘掉有多难
忘掉有多难 2021-01-18 09:25

I have a QTableWidget widget in my application. I have to handle both single-click and double click mouse events separately in my application. Right now, only s

相关标签:
1条回答
  • 2021-01-18 09:55

    Okey, now i see. I had similar problem few weeks ago. The problem is in your QTableWidgetItem. I don't know exactly how does it work, but sometimes you can miss your item and click on cell. That's how you can fix it. Connect it this way:

    connect(ui.tableWidget, SIGNAL(cellClicked(int, int)), this, SLOT(myCellClicked(int, int)));
    connect(ui.tableWidget, SIGNAL(cellDoubleClicked(int,int)), this, SLOT(tableItemClicked(int,int)));
    

    And in your tableItemClicked slot do it this way:

    void MyWidget::tableItemClicked(int row, int column)
    {
        QTableWidgetItem *item = new QTableWidgetItem;
        item = myTable->item(row,column)
        /* do some stuff with item */
    }
    
    0 讨论(0)
提交回复
热议问题