Results 1 to 3 of 3

Thread: how to implement the listwidget delegate?thanks

  1. #1
    Join Date
    Apr 2013
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default how to implement the listwidget delegate?thanks

    i want to implement the listwidget delegate,the code as follows:

    Qt Code:
    1. QWidget *DeComBox::createEditor(QWidget *parent, const QStyleOptionViewItem &option,
    2. const QModelIndex &index) const
    3. {
    4. if(index.column()==0)
    5. {
    6. QListWidget* editor=new QListWidget(parent);
    7. return editor;
    8. }
    9. else{
    10. return QItemDelegate::createEditor(parent, option, index);
    11. }
    12. }
    13.  
    14. void DeComBox::setEditorData(QWidget *editor, const QModelIndex &index) const
    15. {
    16. if(index.column()==0)
    17. {
    18. QListWidget* editor=qobject_cast<QListWidget*>(editor);
    19. editor->addItem("eg1");
    20. editor->addItem("eg2");
    21. editor->addItem("eg3");
    22. editor->addItem("eg4");
    23. editor->setCurrentRow(1);
    24. }
    25. else {
    26. QItemDelegate::setEditorData(editor, index);
    27. }
    28. }
    29.  
    30. void DeComBox::setModelData(QWidget *editor, QAbstractItemModel *model,
    31. const QModelIndex &index) const
    32. {
    33. if(index.column()==0)
    34. {
    35. QListWidget* editor=qobject_cast<QListWidget*>(editor);
    36. model->setData(index,editor->currentItem()->text(),Qt::EditRole);
    37. }
    38. else {
    39. QItemDelegate::setModelData(editor, model, index);
    40. }
    41.  
    42. }
    To copy to clipboard, switch view to plain text mode 


    but not successfully,why, help me , thanks!
    Last edited by Lykurg; 3rd May 2013 at 07:28. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: how to implement the listwidget delegate?thanks

    What do you want to achieve? Returning a list widget as a editor looks strange. How about a QComboBox?

  3. #3
    Join Date
    Apr 2013
    Posts
    3
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: how to implement the listwidget delegate?thanks

    i implement the QComboBox delegate,and i want to know how to implement a listwidget editor or a tablewidget editor even a custom widget (eg. a tablewidget + a pushbutton)? without regard to the list widget's strange looks,how to do it?thanks.

Similar Threads

  1. How to implement delegate in QHeaderView
    By riarioriu3 in forum Newbie
    Replies: 1
    Last Post: 10th August 2012, 06:23
  2. QValidator and ListWidget
    By csvivek in forum Qt Programming
    Replies: 4
    Last Post: 9th July 2008, 19:19
  3. listWidget resize
    By buckadl in forum Qt Tools
    Replies: 3
    Last Post: 12th June 2007, 20:56

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.