PDA

View Full Version : Stuck with QGraphicsItem's setPos() method



salmanmanekia
12th June 2008, 09:42
Hi,
I have encountered the parent/child relationship problem when i tried to use the setPos() method of QGraphicsItem..i am totally stuck with it...how to implement it ,how does it work ...any sample code or conceptual briefing on this would be very helpful....Thanks

salmanmanekia
12th June 2008, 10:05
// HEADER FILE


class exclass :public QObject, public QGraphicsItem
{
Q_OBJECT

public:
exclass(QGraphicsItem *parent = 0);
QRectF boundingRect() const;
void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget);
private:
Ui::exclassClass ui;
};

class playButtonLayout : public exclass
{
private:
QWidget *widg;
QString str;

QPushButton *stopButton;
QPushButton *playButton;
QHBoxLayout *hboxLay;

public:
playButtonLayout();
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget = 0);
};

// MAIN METHOD


int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QGraphicsScene scene(-200,-200,400,400);
exclass *mainScene = new exclass;

mainScene->setPos(1.2,1.2);
scene.addItem(mainScene);
QGraphicsView view(&scene);

view.show();
return a.exec();
}

// SOURCE FILE


#include "exclass.h"

exclass::exclass(QGraphicsItem *parent): QGraphicsItem(parent)
{
playButtonLayout *playLayoutItem = new playButtonLayout();
playLayoutItem->setPos(0,20);
}



QRectF exclass::boundingRect() const
{

}

void exclass::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget)
{

}

playButtonLayout::playButtonLayout()
{
hboxLay = new QHBoxLayout;
playButton = new QPushButton;
stopButton = new QPushButton;
widg = new QWidget;
playButton->setIcon(QIcon("./images/play.JPG"));
stopButton->setIcon(QIcon("./images/stop.JPG"));
hboxLay->addWidget(playButton);
hboxLay->addWidget(stopButton);
widg->setLayout(hboxLay);
str = "salman" ;
}

QRectF playButtonLayout::boundingRect() const
{

}

void playButtonLayout::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget)
{}

I have written this code,i know that some of these things even dont make sense ,but i was trying many things and i also tried this way .....Help would be appreciated