Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

why my qtable widget slightly move on click of last column cell of it ?



  • i have 2 row and 3 column Qtable widget.

    when i click on qtable widget last column it moves slightly.

    i want to disable click on it .

    means i want to use this qtable widget only for display data.

    so what i need to do to make non clickable qtable widget ?



  • @Qt-embedded-developer
    Do it in a loop over all items after you have added them. Or, write a setItem() helper or subclass your QTableWidget/QTableWidgetItems to always set the flags whenever you create a QTableWidgetItem to add into your QTableWidget. There are so many ways.

    Or, try my tableWidget->setEnabled(false) to set the whole QTableWidget disabled in one statement, if the result you get is acceptable to you.



  • @Qt-embedded-developer
    Depending on what you mean, what about QTableWidgetItem::setFlags(Qt::NoItemFlags), or maybe just flags() & ~Qt::ItemIsSelectable?



  • @JonB it gives below error

    error: 'class QTableWidget' has no member named 'setFlags'
    ui->MAGNETOMETERtable_widget->setFlags(Qt::NoItemFlags);



  • @Qt-embedded-developer
    Did you read what I typed? Or look it up? You have not done what I typed.

    If you want to do something on the whole table, try tableWidget->setEnabled(false). But it may make the table look a bit different, you'd have to try it.



  • @JonB Yes i have see this but when i use

    QTableWidgetItem* ptableitem1 = new QTableWidgetItem();
    ptableitem1->setFlags(Qt::NoItemFlags);
    ui->tableWidget->setItem(ui->tableWidget->rowCount()-1,1,ptableitem1);

    but this i need to use again and again for last column all cell . so is there any logic is there which will work generic way for complete QTreewidget ?



  • @Qt-embedded-developer
    Do it in a loop over all items after you have added them. Or, write a setItem() helper or subclass your QTableWidget/QTableWidgetItems to always set the flags whenever you create a QTableWidgetItem to add into your QTableWidget. There are so many ways.

    Or, try my tableWidget->setEnabled(false) to set the whole QTableWidget disabled in one statement, if the result you get is acceptable to you.


Log in to reply