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. multiple columns combobox
Qt 6.11 is out! See what's new in the release blog

multiple columns combobox

Scheduled Pinned Locked Moved Unsolved General and Desktop
8 Posts 3 Posters 4.6k 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.
  • D Offline
    D Offline
    Davidcheng
    wrote on last edited by Davidcheng
    #1

    why does this code not work for qt5.9 ? no item be selectted. i want to make 24 items to 2 columns, each item is clickable

    the code comes from forum

    ui->setupUi(this);
    
        QStandardItemModel model(5, 3);
        for(int i = 0; i < model.rowCount(); i++)
        {
            QStandardItem *col0 = new QStandardItem(QString("foobar%1").arg(i));
            QStandardItem *col1 = new QStandardItem(QString("foo%1").arg(i));
            QStandardItem *col2 = new QStandardItem(QString("bar%1").arg(i));
    
            model.setItem(i, 0, col0);
            model.setItem(i, 1, col1);
            model.setItem(i, 2, col2);
        }
    
        ui->comboBox->setModel(&model);
        QTreeView *treeView = new QTreeView(ui->comboBox);
        ui->comboBox->setView(treeView);
    
        treeView->setColumnHidden(0, true);
        treeView->setSelectionBehavior(QAbstractItemView::SelectRows);
        treeView->setAllColumnsShowFocus(true);
        treeView->setRootIsDecorated(false);
        treeView->header()->hide();
    
    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by mrjj
      #2

      Hi
      The "treeView->setSelectionBehavior(QAbstractItemView::SelectRows);"
      tell it to select whole rows, not cells.
      Try with
      QAbstractItemView::SelectItems

      D 1 Reply Last reply
      2
      • mrjjM mrjj

        Hi
        The "treeView->setSelectionBehavior(QAbstractItemView::SelectRows);"
        tell it to select whole rows, not cells.
        Try with
        QAbstractItemView::SelectItems

        D Offline
        D Offline
        Davidcheng
        wrote on last edited by
        #3

        @mrjj not work, not the reason

        mrjjM 1 Reply Last reply
        0
        • D Davidcheng

          @mrjj not work, not the reason

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @Davidcheng

          well code worked for me so you must provide more details to "not work"
          in order to help you.

          D 1 Reply Last reply
          2
          • VRoninV Offline
            VRoninV Offline
            VRonin
            wrote on last edited by
            #5

            Shooting in the dark here but what about: http://doc.qt.io/qt-5/qcombobox.html#modelColumn-prop

            The default is 0 and you hide that column

            "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

            D 1 Reply Last reply
            1
            • mrjjM mrjj

              @Davidcheng

              well code worked for me so you must provide more details to "not work"
              in order to help you.

              D Offline
              D Offline
              Davidcheng
              wrote on last edited by Davidcheng
              #6

              @mrjj i got this 0_1513602980485_Screenshot from 2017-12-18 21-15-47.png

              1 Reply Last reply
              0
              • VRoninV VRonin

                Shooting in the dark here but what about: http://doc.qt.io/qt-5/qcombobox.html#modelColumn-prop

                The default is 0 and you hide that column

                D Offline
                D Offline
                Davidcheng
                wrote on last edited by
                #7

                @VRonin comment //treeView->setColumnHidden(0, true); does not work.
                could you show the code?

                VRoninV 1 Reply Last reply
                0
                • D Davidcheng

                  @VRonin comment //treeView->setColumnHidden(0, true); does not work.
                  could you show the code?

                  VRoninV Offline
                  VRoninV Offline
                  VRonin
                  wrote on last edited by
                  #8

                  @Davidcheng said in multiple columns combobox:

                  could you show the code?

                  treeView->setModelColumn(1);

                  "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
                  0

                  • Login

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