QTableWidget items



  • I created a QTableWidget and want to have each item/cell of the table editable. When I try to call tableWidget->itemAt(x,y)->setText, the item does not seem to be there (seg fault). I could create a widget for each cell, but it seems very tedious. Is this the way the QTableWidget supposed to be?

    Also none of the cells is editable. I tried in the designer to mark the cell item as editable, but it is not working.

    I don’t see a way to set the column width either. Any help is appreciated.


  • Lifetime Qt Champion

    Hi,

    Did you create all necessary QTableWidgetItems before calling itemAt ? Also be aware that itemAt use mouse coordinates, are you sure you want that ?



  • Yes you are right, should use item(row, col) instead!

    I still have these 2 problems:

    • can not make each cell editable. I specifically set the item to be editable:

    @ QTableWidgetItem *wi = new QTableWidgetItem();
    wi->setFlags(Qt::ItemIsSelectable | Qt::ItemIsEditable | Qt::ItemIsEnabled);
    tableWidget->setItem(row, c, wi);@

    But it does not work

    • How can I specify the width of each column? Tried to set the width for one item, but it does not work.

  • Lifetime Qt Champion

    AFAIK, they are editable by default.

    "setColumnWidth":http://qt-project.org/doc/qt-5/qtableview.html#setColumnWidth is what you are looking after


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.