papillon
22nd April 2014, 22:30
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:
GraphicsItem *parent = 0, QGraphicsScene *scene = 0);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
void mousePressEvent(QGraphicsSceneMouseEvent * event);
.....
}
proxy.cpp
#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();
}
main.cpp
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);
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/31916-Problem-with-QGraphicsScene-QGraphicsProxyWidget-and-setting-widget-focus) but couldn't come up with a solution.
Thanks for any help.
Here is my implementation:
proxy.h
class GENProxy : public QGraphicsProxyWidget
{
public:
GraphicsItem *parent = 0, QGraphicsScene *scene = 0);
protected:
QVariant itemChange(GraphicsItemChange change, const QVariant &value);
void mousePressEvent(QGraphicsSceneMouseEvent * event);
.....
}
proxy.cpp
#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();
}
main.cpp
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);
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/31916-Problem-with-QGraphicsScene-QGraphicsProxyWidget-and-setting-widget-focus) but couldn't come up with a solution.
Thanks for any help.