Results 1 to 19 of 19

Thread: How to create a Combo box in a Tablview Model

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #15
    uzairsaeed702 Guest

    Default [Solved] How to create a Combo box in a Tablview Model

    Finally problem solved after reading again n again about MVC and thanks "All" for the support !!

    I have configured the model with Combo box delegate with openPersistentEditor in combo box enabled columns (4,5) .

    In ComboBoxDelegate.cpp

    Qt Code:
    1. ]QWidget *ComboBoxDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem & option , const QModelIndex &index ) const
    2. {
    3.  
    4.  
    5. if(index.column() == 3 || index.column() == 4)
    6. {
    7.  
    8. // Create the combobox and populate it
    9. QComboBox *cb = new QComboBox(parent);
    10. cb->addItem(QString("Please Select"));
    11. cb->addItem(QString("1"));
    12. cb->addItem(QString("2"));
    13. cb->addItem(QString("3"));
    14. connect(cb, SIGNAL(currentIndexChanged(QString)), this, SLOT(print(QString)));
    15. return cb;
    16. } else
    17. return QStyledItemDelegate::createEditor(parent, option, index);
    18. }
    To copy to clipboard, switch view to plain text mode 
    ]

    And in my TableModel.cpp Class

    Qt Code:
    1. ]
    2. bool TableModel::setData(const QModelIndex & index, const QVariant &value, int role)
    3. {
    4. int row = index.row();
    5. int col = index.column();
    6. QMap<QString, QString> qMapPair = listOfItems.at(index.row());
    7.  
    8.  
    9. if(index.isValid() && role == Qt::EditRole)
    10. {
    11. switch(col) {
    12. case 3 :
    13. {
    14. qDebug() << "Value From Table Model = " <<value.toString() << "Row" <<row << "xCol"<< col ;
    15. return true;
    16. }
    17. break;
    18. case 4 :
    19. {
    20. qDebug() << "Value From Table Model = " <<value.toString() << "Row" <<row << "xCol"<< col ;
    21. return true;
    22. }
    23. break;
    24. default :
    25. break;}}return false;}
    To copy to clipboard, switch view to plain text mode 
    ]

    and things are working perfectly , now i am working on a event that when i will select any index value in combo box it will populate a dialog which configure the data on my Map. I will ask later for further question .
    Last edited by uzairsaeed702; 20th January 2015 at 10:01. Reason: updated contents

Similar Threads

  1. Create Complex combo control
    By frsdot in forum General Programming
    Replies: 1
    Last Post: 20th October 2013, 15:14
  2. Replies: 1
    Last Post: 11th June 2013, 16:56
  3. Value from combo box to LCD
    By dayo30 in forum Qwt
    Replies: 4
    Last Post: 1st February 2013, 00:40
  4. How to create Combo box using QML in Qt
    By Channareddy in forum Newbie
    Replies: 0
    Last Post: 4th July 2011, 05:47
  5. Is it possible to create a combo with paper sizes?
    By aekilic in forum Qt Programming
    Replies: 10
    Last Post: 19th January 2010, 09:16

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.