Hi, I subclassed a QGraphicsProxyWidget and I can successfully add it to the scene. However, I cannot move it around, and it seems that no mouse events are triggered.
Here is my implementation:
proxy.h
class GENProxy : public QGraphicsProxyWidget
{
public:
protected:
.....
}
class GENProxy : public QGraphicsProxyWidget
{
public:
GraphicsItem *parent = 0, QGraphicsScene *scene = 0);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
void mousePressEvent(QGraphicsSceneMouseEvent * event);
.....
}
To copy to clipboard, switch view to plain text mode
proxy.cpp
#include "proxy.h"
.....
{
QFormLayout *layout = new QFormLayout;
layout->addRow(numberLabel, numberEdit);
groupBox->setLayout(layout);
QGraphicsProxyWidget *w = scene->addWidget(groupBox);
w->setFocus();
}
#include "proxy.h"
.....
GENProxy::GENProxy(QGraphicsItem *parent, QGraphicsScene *scene) : QGraphicsProxyWidget(parent)
{
QGroupBox *groupBox = new QGroupBox("Contact Details");
QLabel *numberLabel = new QLabel("Telephone number");
QLineEdit *numberEdit = new QLineEdit;
QFormLayout *layout = new QFormLayout;
layout->addRow(numberLabel, numberEdit);
groupBox->setLayout(layout);
QGraphicsProxyWidget *w = scene->addWidget(groupBox);
w->setFlag(QGraphicsItem::ItemIsMovable,true);
w->setFlag(QGraphicsItem::ItemIsSelectable,true);
w->setFlag(QGraphicsItem::ItemIsFocusable,true);
w->setFocus();
}
To copy to clipboard, switch view to plain text mode
main.cpp
myView
->setRenderHint
(QPainter::Antialiasing);
myView->setSceneRect(0, 0, 800, 800);
myView->setBackgroundBrush(Qt::gray);
vlayout->addWidget(myView);
GENProxy *a = new GENProxy(0, myScene);
QGraphicsScene *myScene=new QGraphicsScene;
QGraphicsView *myView = new QGraphicsView(myScene);
myView->setRenderHint(QPainter::Antialiasing);
myView->setSceneRect(0, 0, 800, 800);
myView->setBackgroundBrush(Qt::gray);
QVBoxLayout* vlayout = new QVBoxLayout(mainClass.Interface.terraformTab);
vlayout->addWidget(myView);
GENProxy *a = new GENProxy(0, myScene);
To copy to clipboard, switch view to plain text mode
As a matter of fact, the only signal showing activity is itemChange, but I can't set the focus or move the proxy around, and signals attached to the proxy embedded widgets aren't firing either (avoided to put those in the above code).
I followed also another thread here (http://www.qtcentre.org/threads/3191...g-widget-focus) but couldn't come up with a solution.
Thanks for any help.
Bookmarks