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. Creating table in QcomboBox
Forum Updated to NodeBB v4.3 + New Features

Creating table in QcomboBox

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 1.3k 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
    devman
    wrote on last edited by
    #1

    I would like to create a combobox with several columns and with column headers. I point out that I am new to programming with Qt. a bit like the image below. Thank you for kindly helping me. thank you.
    MultiColumnComboBoxControl.png

    JonBJ eyllanescE 2 Replies Last reply
    0
    • D devman

      I would like to create a combobox with several columns and with column headers. I point out that I am new to programming with Qt. a bit like the image below. Thank you for kindly helping me. thank you.
      MultiColumnComboBoxControl.png

      JonBJ Online
      JonBJ Online
      JonB
      wrote on last edited by
      #2

      @devman
      This looks like a combobox up top and a separate widget, mostly QTableView/QTableWidget plus buttons and scrolling at the bottom. Would that satisfy you? I don't know whether you can do all this in a combobox delegate.

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

        Hi and welcome to devnet,

        You have two options:

        • set a custom view using QComboBox::setView
        • as @JonB wrote, use a custom QStyledItemDelegate

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

        JonBJ 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi and welcome to devnet,

          You have two options:

          • set a custom view using QComboBox::setView
          • as @JonB wrote, use a custom QStyledItemDelegate
          JonBJ Online
          JonBJ Online
          JonB
          wrote on last edited by
          #4

          @SGaist Oh, I didn't know about QComboBox::setView(), that looks nicely suited for the popup!

          1 Reply Last reply
          0
          • D devman

            I would like to create a combobox with several columns and with column headers. I point out that I am new to programming with Qt. a bit like the image below. Thank you for kindly helping me. thank you.
            MultiColumnComboBoxControl.png

            eyllanescE Offline
            eyllanescE Offline
            eyllanesc
            wrote on last edited by
            #5

            @devman MWE:

            #include <QtWidgets>
            
            int main(int argc, char *argv[])
            {
                QApplication a(argc, argv);
            
                QMainWindow w;
                QComboBox *combo = new QComboBox(&w);
            
                QStandardItemModel model(10, 3);
                model.setHorizontalHeaderLabels({"title", "name", "company"});
                for(int i=0; i< model.rowCount(); ++i){
                    for(int j=0; j < model.columnCount(); ++j){
                        QStandardItem *it = new QStandardItem(QString("%1 - %2").arg(i).arg(j));
                        model.setItem(i, j, it);
                    }
                }
                combo->setModel(&model);
                combo->setModelColumn(1);
            
                QTableView *view = new QTableView;
                combo->setView(view);
                view->setSelectionBehavior(QAbstractItemView::SelectRows);
                view->setFixedWidth(350);
            
                w.show();
            
                return a.exec();
            }
            

            If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

            1 Reply Last reply
            3
            • D Offline
              D Offline
              devman
              wrote on last edited by
              #6

              Thank you all for answering me so quickly, I received to do it with a setView but the columns just take the size of the combobox.or me I would like to display several columns even if the combobox is small.

              eyllanescE 1 Reply Last reply
              0
              • D devman

                Thank you all for answering me so quickly, I received to do it with a setView but the columns just take the size of the combobox.or me I would like to display several columns even if the combobox is small.

                eyllanescE Offline
                eyllanescE Offline
                eyllanesc
                wrote on last edited by eyllanesc
                #7

                @devman Have you run my MWE? In that code I have set the width of the QTableView which is larger than the width of the QComboBox: view->setFixedWidth(350);

                If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

                1 Reply Last reply
                1
                • D Offline
                  D Offline
                  devman
                  wrote on last edited by
                  #8

                  Thank you very much eyllanesc, your code works perfectly

                  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