Select rows and columns in QTableWidget, while keeping highlighted

后端 未结 1 542
囚心锁ツ
囚心锁ツ 2021-01-22 06:31

I have a QTableWidget that I\'ve set up such that you can\'t select the cells, but can select rows/columns by their headers. The problem I\'m having is when I select a row, it d

相关标签:
1条回答
  • 2021-01-22 07:19

    This code allows you to select column first then you must press control to select other rows. Try this, I hope it can help. Anyway, this solution doesn't work well with shift.

    void SO_Qt::hhSelected( int index )
    {
        if(index <= 0) return;
        ui.tableWidget->setSelectionMode(QAbstractItemView::SingleSelection);
        ui.tableWidget->setSelectionBehavior(QAbstractItemView::SelectColumns);
        ui.tableWidget->selectColumn(index);
        ui.tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
    }
    
    void SO_Qt::vhSelected( int index )
    {
        ui.tableWidget->setSelectionMode(QAbstractItemView::ExtendedSelection);
        ui.tableWidget->setSelectionBehavior(QAbstractItemView::SelectItems);
        ui.tableWidget->selectRow(index);
        ui.tableWidget->setSelectionMode(QAbstractItemView::NoSelection);
    }
    

    enter image description here

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