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. HOWTO get a ComboBox in a TableView to activate on a single click?
Forum Updated to NodeBB v4.3 + New Features

HOWTO get a ComboBox in a TableView to activate on a single click?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 7.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.
  • S Offline
    S Offline
    scarleton
    wrote on 11 Apr 2012, 02:39 last edited by
    #1

    I have placed a ComboBox in a TableView. Currently the user needs to double click to get it into edit mode. What do I need to do get it into Edit mode with a single click?

    Sam

    1 Reply Last reply
    0
    • G Offline
      G Offline
      giesbert
      wrote on 11 Apr 2012, 06:44 last edited by
      #2

      You can change the editTrigger of the view.

      Nokia Certified Qt Specialist.
      Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz)

      1 Reply Last reply
      0
      • S Offline
        S Offline
        scarleton
        wrote on 12 Apr 2012, 00:20 last edited by
        #3

        Well, that is a good start, the only problem is that I don't want all cells to be editable. The best option I have found, which I am not a huge fan of, is to subclass the TableView and implement my own custom edit to return false for columns that I don't want to be editable. Is there a better way?

        1 Reply Last reply
        0
        • S Offline
          S Offline
          Sam
          wrote on 15 Apr 2012, 07:43 last edited by
          #4

          Hi,

          You can try the following approach.

          1. For your tableView change the editTrigger

          @ui->tableView->setEditTriggers(QAbstractItemView::AllEditTriggers);@

          1. Then you need to override the Flags function for your model. For eg i have :
            @class MyStandardItemModel : public QStandardItemModel
            {
            public:
            MyStandardItemModel();
            protected:
            Qt::ItemFlags flags(const QModelIndex &index) const;
            };@

          and in the implementation file you can write:

          @Qt::ItemFlags MyStandardItemModel::flags(const QModelIndex &index) const
          {
          Qt::ItemFlags flags = QAbstractItemModel::flags(index);
          if (index.column() == 2) /* here i want column no 2 only to be editable */
          {
          flags |= Qt::ItemIsEditable;
          return flags;
          }
          return QAbstractItemModel::flags(index);
          }@

          This worked for me :)

          1 Reply Last reply
          0
          • S Offline
            S Offline
            scarleton
            wrote on 18 Apr 2012, 01:22 last edited by
            #5

            Thank you! You provided me with the road map I needed to get my results. What I did differently was how I handled the flags. The key was to only enable the edit on the columns I wanted to allow editing. Works like a champ, thank you!!!

            @Qt::ItemFlags InvoiceItemSqlModel::flags(const QModelIndex &index ) const
            {
            Qt::ItemFlags flags = QSqlTableModel::flags(index);

            if( index.column() == productIdNo() ||
            index.column() == qtyNo() ||
            index.column() == priceNo())
            flags |= Qt::ItemIsEditable;
            else
            flags &= ~Qt::ItemIsEditable;

            return flags;
            }@

            1 Reply Last reply
            0
            • S Offline
              S Offline
              Sam
              wrote on 18 Apr 2012, 05:02 last edited by
              #6

              You are welcome!!!!

              1 Reply Last reply
              0

              1/6

              11 Apr 2012, 02:39

              • Login

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