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. QTableView directly shows QComboBox in one column
Forum Updated to NodeBB v4.3 + New Features

QTableView directly shows QComboBox in one column

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 3.1k 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.
  • P Offline
    P Offline
    pmjz
    wrote on last edited by
    #1

    Hi guys

    I want to display QcomboBox in one column. as I searched in forum, I did two things:

    1. go to createEditor() editor->setautoFillBackGround(true)
      2.invoke the openPersistentEditor() in the QtableviewDialog constructor. but it does not work rightly. any advices .thanks in advance.

    @
    void ImportWellsDialog::setImportTableModel(QObject *obj)
    {
    QAbstractItemModel *model = qobject_cast<QAbstractItemModel *>(obj);
    m_importTableModel = model;
    // ui->importTableView->horizontalHeader()->setVisible(true);
    if(model)
    {
    for( int i = 0; i < model->rowCount(); ++i )
    ui->importTableView->openPersistentEditor(model->index(i, 3, QModelIndex()) );

    // ui->importTableView->openPersistentEditor(model->index(1,3,QModelIndex()));
    // ui->importTableView->openPersistentEditor(model->index(2,3,QModelIndex()));
    // ui->importTableView->openPersistentEditor(model->index(3,3,QModelIndex()));
    // ui->importTableView->openPersistentEditor(model->index(4,3,QModelIndex()));
    // ui->importTableView->openPersistentEditor(model->index(5,3,QModelIndex()));
    // ui->importTableView->openPersistentEditor(model->index(6,3,QModelIndex()));
    // ui->importTableView->openPersistentEditor(model->index(7,3,QModelIndex()));
    // ui->importTableView->openPersistentEditor(model->index(1,5,QModelIndex()));
    }
    ui->importTableView->setModel(model);
    }

    QWidget *WellsComboBoxDelegate::createEditor(QWidget *parent,
    const QStyleOptionViewItem &option,
    const QModelIndex &index) const
    {
    // if(index.column() == 2)
    // {
    // for(int i = 0; i < list.size(); i++)
    // {
    // editor->addItem(list.at(i)->data(0).toString());//abbreviation's role is 0
    // }
    // Guard::checkIfTrue(QObject::connect(editor, SIGNAL(activated(int )),
    // this, SLOT(comboBoxdataChanged(int))),HERE);
    // }
    if(((index.column() == 3)&&(index.row() != 0)) ||
    ((index.column() == 5)&&(index.row() == 1)))
    {
    QComboBox *editor = new QComboBox(parent);
    editor->setEditable(false);
    editor->setAutoFillBackground(true);
    return editor;

    }
    

    }
    @

    [Edit: Added code formatting. Please wrap your code in @ tags; mlong]

    1 Reply Last reply
    0
    • G Offline
      G Offline
      goetz
      wrote on last edited by
      #2

      I'm not sure what you want to achieve. If you need the combo boxes permanently, try "QAbstractItemView::setIndexWidget() ":http://doc.qt.nokia.com/4.7/qabstractitemview.html#setIndexWidget

      http://www.catb.org/~esr/faqs/smart-questions.html

      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