I have created two graphics items object and tried to set position of them by using setPos but surprsingly it doesnt work...one item is for displaying text and one item is for displaying a widget...when i only create a object for displaying text ,it works fine and set pos works well,but if i only create a instant for widget item and use setPos it doesnt work,and also if i try to use both of them so that both are shown in the view at the same time ,,this also doesnt works...!!!..may be code would be much more helpful
// MAIN FUNCTION //
#include "exclass.h"
#include <QApplication>
#include <QGraphicsScene>
int main(int argc, char *argv[])
{
exclass *lay = new exclass;
Horlay *txt = new Horlay;
lay->Widgt(&scene);
txt->Strng(&scene);
lay->setPos(5,5);
txt->setPos(500,500);
view.
setBackgroundBrush(QPixmap(":/images/background.JPG"));
view.setScene(&scene);
view.show();
return a.exec();
}
#include "exclass.h"
#include <QApplication>
#include <QGraphicsScene>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
exclass *lay = new exclass;
Horlay *txt = new Horlay;
QGraphicsScene scene;
QGraphicsView view;
lay->Widgt(&scene);
txt->Strng(&scene);
lay->setPos(5,5);
txt->setPos(500,500);
view.setBackgroundBrush(QPixmap(":/images/background.JPG"));
view.setScene(&scene);
view.show();
return a.exec();
}
To copy to clipboard, switch view to plain text mode
// HEADER CLASS //
#ifndef EXCLASS_H
#define EXCLASS_H
#include <QtGui/QWidget>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsItem>
#include <QPainter>
#include <QImage>
#include <QPushButton>
#include <QHBoxLayout>
{
public:
};
{
public:
};
#endif // EXCLASS_H
#ifndef EXCLASS_H
#define EXCLASS_H
#include <QtGui/QWidget>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QGraphicsItem>
#include <QPainter>
#include <QImage>
#include <QPushButton>
#include <QHBoxLayout>
class exclass : public QGraphicsItem
{
public:
QPushButton *stopButton;
QPushButton *playButton;
QHBoxLayout *hboxLay;
QWidget *widg;
exclass(QGraphicsItem *parent = 0);
void Widgt(QGraphicsScene *);
QRectF boundingRect() const;
void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget);
};
class Horlay :public QGraphicsItem
{
public:
QString str;
Horlay(QGraphicsItem *parent = 0);
void Strng(QGraphicsScene *);
QRectF boundingRect() const;
void paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget);
};
#endif // EXCLASS_H
To copy to clipboard, switch view to plain text mode
// SOURCE CLASS //
#include "exclass.h"
{
playButton
->setIcon
(QIcon(":/images/play.JPG"));
stopButton
->setIcon
(QIcon(":/images/stop.JPG"));
}
{
hboxLay->addWidget(playButton);
hboxLay->addWidget(stopButton);
widg->setLayout(hboxLay);
scene->addWidget(widg);
}
QRectF exclass
::boundingRect() const {
}
{
}
{
}
{
str = "salman" ;
scene->addText(str);
}
{
}
QRectF Horlay
::boundingRect() const {
}
#include "exclass.h"
exclass::exclass(QGraphicsItem *parent):QGraphicsItem(parent)
{
hboxLay = new QHBoxLayout;
playButton = new QPushButton;
stopButton = new QPushButton;
widg = new QWidget;
playButton->setIcon(QIcon(":/images/play.JPG"));
stopButton->setIcon(QIcon(":/images/stop.JPG"));
}
void exclass::Widgt(QGraphicsScene *scene)
{
hboxLay->addWidget(playButton);
hboxLay->addWidget(stopButton);
widg->setLayout(hboxLay);
scene->addWidget(widg);
}
QRectF exclass::boundingRect() const
{
}
void exclass::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget)
{
}
Horlay::Horlay(QGraphicsItem *parent):QGraphicsItem(parent)
{
}
void Horlay::Strng(QGraphicsScene *scene)
{
str = "salman" ;
scene->addText(str);
}
void Horlay::paint(QPainter *painter,const QStyleOptionGraphicsItem *option,QWidget *widget)
{
}
QRectF Horlay::boundingRect() const
{
}
To copy to clipboard, switch view to plain text mode
Bookmarks