[SOLVED] How i can show Qtableview in Qcombobox



  • 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



  • HI, you can read the documentation:

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



  • 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;

    }@


  • Moderators

    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?!



  • 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;
    

    }
    @



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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.