Results 1 to 13 of 13

Thread: custom widget in delegate

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Feb 2014
    Posts
    60
    Thanks
    4
    Thanked 5 Times in 5 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default custom widget in delegate

    Hi,
    I need to show custom widget(lineEdit +PushButton) on double click of QTreeview so i have created my own Delegate but for some reason the widget is not shown.I have createEditor() method override in delegate.Here is a sample Code i have done.I have not implemented the paint method to render the data but my problem is the widget doesn't shown when create editor called.Guide me on this

    MainWindow.cpp

    Qt Code:
    1. for (int row = 0; row < 4; ++row) {
    2. for (int column = 0; column < 4; ++column) {
    3. QStandardItem *item = new QStandardItem(QString("row %0, column %1").arg(row).arg(column));
    4. model->setItem(row, column, item);
    5. }
    6. }
    7.  
    8. QTreeView *veiw = new QTreeView(this);
    9. MyDelegate *del = new MyDelegate;
    10. veiw->setItemDelegate(del);
    11. veiw->setModel(model);
    12.  
    13. setCentralWidget(veiw);
    To copy to clipboard, switch view to plain text mode 

    MyDelegate.cpp

    Qt Code:
    1. QWidget *MyDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const
    2. {
    3. if(index.column() == 0)
    4. return new CustomWidget(parent);
    5. if(index.column() == 1)
    6. return new QComboBox(parent);
    7.  
    8. }
    To copy to clipboard, switch view to plain text mode 

    CustomWidget.cpp

    Qt Code:
    1. CustomWidget::CustomWidget(QWidget *parent) : QWidget(parent)
    2. {
    3. QLineEdit *edit = new QLineEdit;
    4. QHBoxLayout *layout = new QHBoxLayout;
    5. layout->addWidget(edit);
    6. layout->addWidget(but);
    7. setLayout(layout);
    8. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

Similar Threads

  1. Replies: 5
    Last Post: 30th October 2014, 20:40
  2. Replies: 1
    Last Post: 10th May 2011, 22:35
  3. Custom Model? Custom View? Custom Delegate?
    By Doug Broadwell in forum Newbie
    Replies: 4
    Last Post: 11th February 2010, 20:23
  4. Replies: 0
    Last Post: 1st February 2010, 11:00
  5. Question about custom view (or custom delegate)
    By skuda in forum Qt Programming
    Replies: 1
    Last Post: 21st September 2009, 20:06

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.