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 with different types
Qt 6.11 is out! See what's new in the release blog

QTableWidget with different types

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 4 Posters 8.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.
  • E Offline
    E Offline
    evergreen
    wrote on last edited by SGaist
    #1

    Hello, I would like to display an editable QTableWidget, but with some item only editable as int and some others as strings.
    I can't find a solution in the doc.

    Is it possible? How could it be done?

    Thanks

    1 Reply Last reply
    0
    • S Offline
      S Offline
      silver47
      wrote on last edited by
      #2

      Well, you can set any widget into Cell, for example:
      QLineEdit for strings and QSpinBox for digits.
      @QTableWidget::setCellWidget ( int row, int column, QWidget * widget )@

      sorry for my english :(

      1 Reply Last reply
      0
      • E Offline
        E Offline
        evergreen
        wrote on last edited by
        #3

        That's a good idea. Thanks.

        However, I've just tested it and there's a problem :
        My QTableWidget is composed by about a thousand cells. So when I apply the method that create QLineEdit or QSpinBox, it takes about 5 seconds to display while when I was using only QTableWidgetItem it was immediate.

        So, If someone know a way to specify the type of a QTableWidgetItem, it would be much better.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          silver47
          wrote on last edited by
          #4

          QTableWidget provides basicaly possibility and works slowly. For more flexible possibility use QStandardItemModel & QTableView or QAbstractItemModel & QTableView

          sorry for my english :(

          1 Reply Last reply
          0
          • E Offline
            E Offline
            evergreen
            wrote on last edited by
            #5

            I found a more simple solution with the class QIntValidator
            I put a QLineEdit with this validator on the item of the table I want to edit.
            Works perfectly.

            Thanks for helps.

            1 Reply Last reply
            0
            • M Offline
              M Offline
              MrMaavin
              wrote on last edited by
              #6

              I used this solution where you have a QLineEdit in each cell.

              for(int trow=0; trow <= 2; trow++ )
                  {
                      for(int tcolumn=0; tcolumn <= 3; tcolumn++ )
                      {
                          QLineEdit * tableline = new QLineEdit;
                          tableline->setValidator( new QDoubleValidator(0, 100, 2, this) );
                          ui->tableWidget->setCellWidget ( trow, tcolumn,  tableline);
                      }
              }
              1 Reply Last reply
              1
              • VRoninV Offline
                VRoninV Offline
                VRonin
                wrote on last edited by
                #7

                probably it's just my personal and never ending hate for setCellWidget but, especially for cases like this one where it applies to many cells, a combination of setFlag and a QStyledItemDelegate derived class is the way to go

                "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
                ~Napoleon Bonaparte

                On a crusade to banish setIndexWidget() from the holy land of Qt

                1 Reply Last reply
                1

                • Login

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