5

Qt 5.5 has a virtual method to define a custom widget for editing mode:

QWidget *createEditor(QWidget *parent,const QStyleOptionViewItem & option ,const QModelIndex & index ) const

But how to use a custom widget to override the "view" mode? I saw "stars rating" delegate example where paint method is used but that's not what I need. I need to show a custom widget that contains other standard widgets inside it and use it in a view mode of QTableView or QListView. No need to get mess with painting pointers and figures - just show a custom widget (that has .ui file) and contains other standard widgets with their behaviour.

For example: There is a download manager application that can show downloads either as a table or list view. QListView with a list of downloads. Each download has URL, Title, TotalSize, DownloadedSize, ProgressBar, Pause button, Remove button, Resume button. All of those can be columns in a table (QTableView) or composed similar to HTML's DIV in one cell (QListView widget)

How to achieve it? Is there anything like QWidget *createViewer(... ?

QtWidgets are used no QML.

3
  • 1
    Why it should be a widget in viewing mode?
    – vahancho
    Commented Oct 27, 2015 at 10:08
  • @vahancho very common example - QListView with a list of downloads. Each download has URL, Title, TotalSize, DownloadedSize, ProgressBar, Pause button, Remove button, Resume button. All of those can be columns in a table (QTableView) or composed similar to HTML's DIV in one cell (QListView widget)
    – Zelid
    Commented Oct 27, 2015 at 10:14
  • 1
    You might try to use QListWidget and QListWidget::openPersistentEditor() function to show the editor in viewing mode.
    – vahancho
    Commented Oct 27, 2015 at 10:30

1 Answer 1

1

For static content you can use QAbstractItemView::setIndexWidget.

For dynamic content the only option is to implement paint method in you delegate class.

Not the answer you're looking for? Browse other questions tagged or ask your own question.