aditya.kaole
8th September 2010, 08:46
I am using QGraphicsGridLayout in GraphicScene(class publicly inherited from QGraphicsScene)..
I have to place a QPushButton in column 1 of the QGraphicsGridLayout in all the rows. And want to place a QGraphicsItem into column 2 of each row..
I am able to see the two QPushButton one below another (after adding them in the QGraphicsGridLayout), but when i try to add the QGraphicsItem (GraphicsItem). they are placed at zero location of the scene.. And are not placed in the particular grid column location.
I don't want use the hard coded location (using setpos() ) for the QGraphicsItem. How can i do that?
Code snap shot:
================================
GraphicScene::GraphicScene(QWidget *parent)
{
setItemIndexMethod(QGraphicsScene::NoIndex);
setSceneRect(0, 0, 800, 1200);
graphics_scene_layout = new QGraphicsGridLayout();
QGraphicsProxyWidget *proxy_p_button_0 = new QGraphicsProxyWidget();
QGraphicsProxyWidget *proxy_p_button_1 = new QGraphicsProxyWidget();
QGraphicsProxyWidget *proxy_graphicsitem_0 = new QGraphicsProxyWidget();
QGraphicsProxyWidget *proxy_graphicsitem_1 = new QGraphicsProxyWidget();
QPushButton *p_button_0 = new QPushButton("-");
p_button_0->resize(20,20);
QPushButton *p_button_1 = new QPushButton("-");
p_button_1->resize(20,20);
proxy_p_button_0->setWidget(p_button_0);
proxy_p_button_1->setWidget(p_button_1);
p_button_0->show();
p_button_1->show();
graphics_scene_layout->addItem(proxy_p_button_0, 0, 0, Qt::AlignLeft | Qt::AlignTop);
graphics_scene_layout->addItem(proxy_p_button_1, 1, 0, Qt::AlignLeft | Qt::AlignTop);
GraphicsItem *item0 = new GraphicsItem(parent);
GraphicsItem *item1 = new GraphicsItem(parent);
proxy_graphicsitem_0->setGraphicsItem(item0);
proxy_graphicsitem_1->setGraphicsItem(item1);
graphics_scene_layout->addItem(proxy_graphicsitem_0, 0, 1);
graphics_scene_layout->addItem(proxy_graphicsitem_1, 1, 1);
QGraphicsWidget *form = new QGraphicsWidget;
form->setLayout(graphics_scene_layout);
this->addItem(form);
}
================================
Am i missing some thing?? I was expecting placing the item in correct gird row/column will take care of position in scene.
Thanks in Advance!
I have to place a QPushButton in column 1 of the QGraphicsGridLayout in all the rows. And want to place a QGraphicsItem into column 2 of each row..
I am able to see the two QPushButton one below another (after adding them in the QGraphicsGridLayout), but when i try to add the QGraphicsItem (GraphicsItem). they are placed at zero location of the scene.. And are not placed in the particular grid column location.
I don't want use the hard coded location (using setpos() ) for the QGraphicsItem. How can i do that?
Code snap shot:
================================
GraphicScene::GraphicScene(QWidget *parent)
{
setItemIndexMethod(QGraphicsScene::NoIndex);
setSceneRect(0, 0, 800, 1200);
graphics_scene_layout = new QGraphicsGridLayout();
QGraphicsProxyWidget *proxy_p_button_0 = new QGraphicsProxyWidget();
QGraphicsProxyWidget *proxy_p_button_1 = new QGraphicsProxyWidget();
QGraphicsProxyWidget *proxy_graphicsitem_0 = new QGraphicsProxyWidget();
QGraphicsProxyWidget *proxy_graphicsitem_1 = new QGraphicsProxyWidget();
QPushButton *p_button_0 = new QPushButton("-");
p_button_0->resize(20,20);
QPushButton *p_button_1 = new QPushButton("-");
p_button_1->resize(20,20);
proxy_p_button_0->setWidget(p_button_0);
proxy_p_button_1->setWidget(p_button_1);
p_button_0->show();
p_button_1->show();
graphics_scene_layout->addItem(proxy_p_button_0, 0, 0, Qt::AlignLeft | Qt::AlignTop);
graphics_scene_layout->addItem(proxy_p_button_1, 1, 0, Qt::AlignLeft | Qt::AlignTop);
GraphicsItem *item0 = new GraphicsItem(parent);
GraphicsItem *item1 = new GraphicsItem(parent);
proxy_graphicsitem_0->setGraphicsItem(item0);
proxy_graphicsitem_1->setGraphicsItem(item1);
graphics_scene_layout->addItem(proxy_graphicsitem_0, 0, 1);
graphics_scene_layout->addItem(proxy_graphicsitem_1, 1, 1);
QGraphicsWidget *form = new QGraphicsWidget;
form->setLayout(graphics_scene_layout);
this->addItem(form);
}
================================
Am i missing some thing?? I was expecting placing the item in correct gird row/column will take care of position in scene.
Thanks in Advance!