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. [SOLVED] How i can show Qtableview in Qcombobox
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] How i can show Qtableview in Qcombobox

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

    Hi, every body

    i see many applications using this method, they shows a table in combobox popup

    is this possible with Qt ? if so, how we can do this

    1 Reply Last reply
    0
    • D Offline
      D Offline
      dbzhang800
      wrote on last edited by
      #2

      HI, you can read the documentation:

      @
      void QComboBox::setView(QAbstractItemView * itemView)
      @

      1 Reply Last reply
      0
      • A Offline
        A Offline
        advseo32
        wrote on last edited by
        #3

        i have implemented this in customdelegate but not working

        i have read, the documentation of setView in Qtassistant , he says
        that if we use (QListWidget, QTableWidget or QTreeWidget) make sure to call setModel() on the combobox with the convenience widgets model before calling this function.

        but i don't know how i can setModel() to Qcombobox
        @
        QWidget *comboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
        {
        if(index.column() != 1 )
        return QStyledItemDelegate::createEditor(parent, option, index);

        QComboBox* editor = new QComboBox(parent);
        QTableWidget *viewTableVente = new QTableWidget(parent);
        QStringList listTable;
        listTable << "N° article" << "Désignation" << "Qte" << "Prix/U" <<             "Montant";
        viewTableVente->setRowCount(1);
        viewTableVente->setColumnCount(5);
        viewTableVente->setHorizontalHeaderLabels(listTable);
        

        editor->setModel(???????????????) ;
        editor->setView(viewTableVente);
        return editor;

        }@

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          and where is your data coming from? Why do you wanna use a QTableView in first place when you don't even have a idea how your model will look like?!

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

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

            Why do you wanna use a QTableView ??
            i have use Qtablewidget just for try, so i must use Qtableview because my data is not editable

            in first place when you don’t even have a idea how your model will look like?!

            i haven't not an idea if use the model of myQtableview or another model
            Stupidity!! :)
            now it working thank's

            @ if(index.column() != 1 )
            return QStyledItemDelegate::createEditor(parent, option, index);

            QComboBox* editor = new QComboBox(parent);
            editor->setStyleSheet("QComboBox { border: 1px solid gray;"
                                  "border-radius: 3px;"
                                   "}"
                                  );
            
            QTableView *designationTableView = new QTableView(parent);
            editor->setModel(m_designationModel);
            editor->setView(designationTableView);
            editor->setEditable(true);
            if(m_db->open())
            {
                m_designationModel->setQuery("select * from Produit");
                designationTableView->setModel(m_designationModel);
            
            }
                return editor;
            

            }
            @

            1 Reply Last reply
            0
            • JeroentjehomeJ Offline
              JeroentjehomeJ Offline
              Jeroentjehome
              wrote on last edited by
              #6

              Add [SOLVED] to your first post, if you think the issue is solved.

              Greetz, Jeroen

              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