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. Tableview style and delegate behavior in Qt
Forum Updated to NodeBB v4.3 + New Features

Tableview style and delegate behavior in Qt

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 1.9k 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.
  • Z Offline
    Z Offline
    Zarkon
    wrote on last edited by
    #1

    Hi,

    I got Tableview and a delegate based on qcombobox set for a certain column. When the tableview is shown I don't see the delegate. I only see it when I start editing the value. Is it possible to see the combobox all the time and not just when editing?

    Greetings

    1 Reply Last reply
    0
    • Z Offline
      Z Offline
      Zarkon
      wrote on last edited by
      #2

      The code is something like this:

      @class comboBoxDelegate : public QItemDelegate
      {
      Q_OBJECT
      public:
      comboBoxDelegate(QObject *parent = 0);

       QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option,
                             const QModelIndex &index) const;
       void setEditorData(QWidget *editor, const QModelIndex &index) const;
       void setModelData(QWidget *editor, QAbstractItemModel *model,
                         const QModelIndex &index) const;
       void updateEditorGeometry(QWidget *editor,
           const QStyleOptionViewItem &option, const QModelIndex &index) const;
      

      };

      ui->tableView->setModel(tableModel);
      comboBoxDelegate *pComboBoxDelegate = new ComboBoxDelegate();
      ui->tableView->setItemDelegateForColumn(1, pComboBoxDelegate);@

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zeljko
        wrote on last edited by
        #3

        Don't know if it'll help to you.I'm doing same thing but in another way. When editor isn't visible then just draw combobox in paintEvent of QTableWidget viewport in cells where combobox is editor, by using QStyle,QStyleOption and friends. It's much faster than show real combobox in each cell.

        1 Reply Last reply
        0
        • Z Offline
          Z Offline
          Zarkon
          wrote on last edited by
          #4

          I look into it. My intention was to use a tableview rather than a tablewidget since I expect we have to address a large amount of data.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            You can pull the same trick with QTableView, only you'll need to use a delegate to do the painting.

            However, note that it will take some effort to make it work like a combo box. Clicking on it will only activate the cell for editing, but the click won't be a click on the real combobox as that does not exist yet. Your users may get frustrated by objects in your table that look like a combobox, but don't act like one.

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              Zarkon
              wrote on last edited by
              #6

              After consultation with my project manager we decided to change the setup a bit so in effect this is not an issue any more, but I think it can easily turn up again. I still have some problems with delegates. The non-edit state, still showed in the background when the editor was active, also the row height did not change when it should have leaving some objects clipped. But that's a story for another time.

              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