Results 1 to 3 of 3

Thread: QItemDelegate use in QTableWidget

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2008
    Posts
    35
    Thanks
    13
    Thanked 2 Times in 2 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default QItemDelegate use in QTableWidget

    Hi,

    delegate class
    Qt Code:
    1. QCLDelegate::QCLDelegate(QObject *parent)
    2. : QItemDelegate(parent)
    3. {
    4. }
    5.  
    6. QWidget *QCLDelegate::createEditor(QWidget *parent,
    7. const QStyleOptionViewItem & /* option */,
    8. const QModelIndex &index) const
    9. {
    10. QComboBox *comboBox = new QComboBox(parent);
    11. if (index.column() == 2) {
    12. for(int i = 1970; i < 2014 ; i++){
    13. QVariant v(i);
    14. comboBox->addItem(v.toString());
    15. }
    16. } else if (index.column() == 3) {
    17. comboBox->addItem(tr("BRRip"));
    18. comboBox->addItem(tr("DVDRip"));
    19. comboBox->addItem(tr("Blu-Ray"));
    20. comboBox->addItem(tr("Other"));
    21. } else if (index.column() == 4) {
    22. comboBox->addItem(tr("Yes"));
    23. comboBox->addItem(tr("No"));
    24. }
    25. connect(comboBox, SIGNAL(activated(int)), this, SLOT(emitCommitData()));
    26.  
    27. return comboBox;
    28. }
    To copy to clipboard, switch view to plain text mode 

    and here is how i add to the table widget

    Qt Code:
    1. bool QCLMovies::parseElements(QDomNode &c, int row)
    2. {
    3. while(!c.isNull()){
    4. QDomElement k = c.toElement();
    5. if(k.text().isEmpty())
    6. return false;
    7. if(labels.indexOf(k.tagName()) == -1)
    8. return false;
    9. //Adding to table widget
    10. setItem(row, labels.indexOf(k.tagName()), new QTableWidgetItem(k.text()));
    11. c = c.nextSibling();
    12. }
    13.  
    14. return true;
    15. }
    To copy to clipboard, switch view to plain text mode 

    the class declaration is QCLMovies: public QTableWidget

    I am trying to read an XML file into the QTableWidget, with columns 2,3 and 4 as combo boxed and columns 0 and 1 as Qtablewidgetitem (QString), but when i start the application it shows all combo boxes..

    Please help me out

    Thanks
    Last edited by arpspatel; 26th October 2009 at 22:46. Reason: updated contents

Similar Threads

  1. QComboBox in QTableWidget : display troubles.
    By Nyphel in forum Qt Programming
    Replies: 2
    Last Post: 13th October 2007, 23:29
  2. QTableWidget issues
    By Djony in forum Qt Programming
    Replies: 42
    Last Post: 19th December 2006, 23:27
  3. print QTableWidget
    By chak_med in forum Qt Programming
    Replies: 3
    Last Post: 4th November 2006, 18:46
  4. QTableWidget editing question
    By Trasmeister in forum Qt Programming
    Replies: 1
    Last Post: 20th September 2006, 18:46
  5. Replies: 6
    Last Post: 5th March 2006, 21:05

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.