Hi.. I tried your suggestion, program compiles but it gets hang and suggests me to close the application. I had given view->setscene(scene) directly only once in the constructor. pixmap was not moving on the view bith timer based Pixmap and button click pixmap, Please have a look. Now the code is almost same but timer based pixmap and click event based pixmap both appears but the issue is. Timer based pixmap is coming like route trace mutilple images(as shown in the earlier posted image). Im searching how to set initially at the constructor level and just to call SetPos at timer slot on the graphicitempixmap.
regarding the x,y co-ordinates, points are coming at client side. by getting the values of x,y at timer interval,it has to update on the application screen.
In my code what changes are expected, to move the timer pixmap without continous adding og pixmap and inserting click based pixmap on the scene.
ui(new Ui::SERVER)
{
ui->setupUi(this);
timer.start(2000);
...............connection signal slot on timer out.....
void SERVER::timeout_123()
{
x=x+2;
y=y+2;
ui->graphicsView->setScene(scene);
GIpix1->setPos(x,y);
}
void SERVER::on_pushButton_clicked()
{
qDebug("inserting new item");
ui->graphicsView->setScene(scene);
GIpix2->setPos(650,150);
}
SERVER::SERVER(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::SERVER)
{
ui->setupUi(this);
scene=new QGraphicsScene(0,0,740,400);
scene=new QGraphicsScene(ui->graphicsView);
timer.start(2000);
...............connection signal slot on timer out.....
void SERVER::timeout_123()
{
x=x+2;
y=y+2;
QPixmap pix1(":/t23_1.png");
QGraphicsPixmapItem *GIpix1=scene->addPixmap(pix1);
ui->graphicsView->setScene(scene);
GIpix1->setPos(x,y);
}
void SERVER::on_pushButton_clicked()
{
qDebug("inserting new item");
QPixmap pix2(":/pin30_red.png");
QGraphicsPixmapItem *GIpix2= scene->addPixmap(pix2);
ui->graphicsView->setScene(scene);
GIpix2->setPos(650,150);
}
To copy to clipboard, switch view to plain text mode
#ifndef SERVER_H
#define SERVER_H
#include <QMainWindow>
#include <QPushButton>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QBrush>
#include <QGraphicsItem>
#include <QGraphicsPixmapItem>
#include <QTimer>
#include <QDebug>
#include <QPixmap>
Q_OBJECT
public:
~SERVER();
protected:
private:
Ui::SERVER *ui;
unsigned int x,y;
private slots:
void on_pushButton_clicked();
};
#endif // SERVER_H
#ifndef SERVER_H
#define SERVER_H
#include <QMainWindow>
#include <QPushButton>
#include <QGraphicsView>
#include <QGraphicsScene>
#include <QBrush>
#include <QGraphicsItem>
#include <QGraphicsPixmapItem>
#include <QTimer>
#include <QDebug>
#include <QPixmap>
class SERVER : public QMainWindow {
Q_OBJECT
public:
SERVER(QWidget *parent = 0);
~SERVER();
protected:
void changeEvent(QEvent *e);
private:
Ui::SERVER *ui;
QGraphicsView *view;
QGraphicsScene *scene;
QPixmap *pix1,*pix2;
QGraphicsItem *GIpix1,*GIpix2;
QTimer *timer;
unsigned int x,y;
private slots:
void on_pushButton_clicked();
};
#endif // SERVER_H
To copy to clipboard, switch view to plain text mode
Bookmarks