Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QTableWidget items
Qt 6.11 is out! See what's new in the release blog

QTableWidget items

Scheduled Pinned Locked Moved General and Desktop
4 Posts 2 Posters 1.4k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • R Offline
    R Offline
    registerme
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        registerme
        wrote on last edited by
        #3

        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.
        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          AFAIK, they are editable by default.

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

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved