We have a custom widget that we want to use as item(cell) widget in QListView. And we don't want to use QListWidget. So is there any way to use our custom widget for a cell in QListView. The delegate seems to have a paint() method , but there is no method from which we can return the custom widget that we want to use for a cell. Can any one please help regarding this? Thanks in advance.
Related
I know it is possible to call setFixedSize() to widget and it will be "inactive" but i want to know is it possible to hide it at all.
So you can try like this in constructor of MainWindow class:
this->statusBar()->setSizeGripEnabled(false);
I'm stuck. With QTableView + QStandartItemModel + QSortFilterProxyModel I can only add 1 QLineEdit for 1 specific column line_edit.textChanged.connect(filter_model.setFilterRegExp). Moreover I can't figure out how to add widget item to QTableView but only to QTableWidget (which i can't use because of filter?). I may give up the idea of adding widget and just make my whole row open another dialog on double click.But still I don't understand how to filter multiple columns at the same time. Thanks in advance
Moreover I can't figure out how to add widget item to QTableView
You need use QtGui.QItemDelegate for such thing. Have a look at this nice code snippet (not mine). And please read Qt manual about QItemDelegate and Model View Delegate pattern.
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.
For static content you can use QAbstractItemView::setIndexWidget.
For dynamic content the only option is to implement paint method in you delegate class.
I want to implement my own Widgets for a QListView. Like this:
If i click on this widget i want to do something.
In time, I only have experience with the QML-Version of the ListView.
Can someone explain how to insert this widget to the a QListView?
Greetings
UPDATE
In my Project i want a GUI like this:
In my first ListView I want to show items, that has a ListView, too. The text of each item can to be update.
There are 2 ways:
Set custom widget for each index: QAbstractItemView::setIndexWidget. Note: there may be problems with interaction with widgets. This way is typically used only for displaying static content.
Create custom QStyledItemDelegate and override editorEvent method. See model-view programming for details.
Update:
I propose you next design:
Create widget with image list + "dynamic content" + labels
Create ScrollArea with vertical layout and add there widgets (1.)
(2.) is prefferable than simple listview, because listview doesn't design for such cases. Listview designed for showing some data, but not to be a container for other complex widgets.
Pros: you will have fully interactable widgets.
Cons: you need to code a bit ;)
I have a widget container I wish to manually paint.
However, it is located within my GUI's MainWindow class.
Is there any way I can register on the paint event for a specific QWidget, so my own function will be called ?
Look for eventFilter. It will help you
The most straightforward way would be to override the paintEvent on the widget
you would like to draw in a custom subclass, and then use that class in your GUI.