Reputation: 4480
How to Add QListView/QListWidget to QGraphicsScene and add Widgets to ListView When i Try to add QLisView to QGraphicsScene mouse scroll affects goes from Scene. I want to add QPushButtons as ListView Items in QgraphicsScene with mouse scroll affect. Thanks.
Upvotes: 0
Views: 1136
Reputation: 91
I second the answer above: ProxyWidget is the answer.
Here is my working code, Header:
class CenterScreen{
private:
QListWidget* nameListWidget;
QGraphicsProxyWidget* nameProxyWidget;
...
C++ source:
void CenterScreen::addListView()
{
QGraphicsScene* scene = ui.centerGraphicsView->scene();
nameListWidget = new QListWidget();
nameProxyWidget = scene->addWidget(nameListWidget);
...
nameProxyWidget->hide(); // you can control your widget as you like
Upvotes: 0
Reputation: 3835
What about QGraphicsProxyWidget
?
QListView *listView = new QListView;
QGraphicsProxyWidget *proxy = scene.addWidget(listView);
Then (or before that) you can populate the list with anything you want. QPushButton
can be added to the list using setIndexWidget()
. Also you might rethink the whole idea of having a QListView
, and give it a try with QScrollArea
and a linear layout containing buttons. That would require a bit more logic to organize items within the scroll area, but it should be more lightweight that QListView
with custom widgets.
Upvotes: 1