PDA

View Full Version : QGraphicsView::translate



peace_comp
4th April 2008, 22:50
Hi..
I Have a trouble to choose the right values for the QGraphicsView::translte method..
My graphicsView contains a map ..and I disabled the scrollBar which is generated automaticly by the class..inseatd I wanna use some Actions To allow a translate right,left,up and down..

connect(actionPan_right,SIGNAL(triggered()),this,S LOT(Right()));
connect(actionPan_left,SIGNAL(triggered()),this,SL OT(Left()));
connect(actionPan_up,SIGNAL(triggered()),this,SLOT (Up()));
connect(actionPan_down,SIGNAL(triggered()),this,SL OT(down()));

....


void gpsinterface::Right(){
graphicsView->translate(1.5,0);
}
void gpsinterface::Left(){
graphicsView->translate(-1.5,0);
}
void gpsinterface::Up(){
graphicsView->translate(0,1.5);
}
void gpsinterface::down(){
graphicsView->translate(0,-1.5);
}


..sometime it works with the pan right but the othrs are still inactive?!!

Plz if someOne had used that method befor could help !!
thanks

maverick_pol
5th April 2008, 00:28
Could you paste your code, or at least a piece of it? Thanks

kacper

peace_comp
5th April 2008, 15:36
class gpsinterface : public QMainWindow , private Ui::gpsinterface
{
Q_OBJECT

public:
gpsinterface(QWidget *parent = 0);
private slots:


void Left();
void Right();
void Up();
void Down();
void ZoomIn();
void ZoomOut();


private:

QGraphicsScene *scene;

};

//**********************file.cpp******************** ************
gpsinterface::gpsinterface(QWidget *parent) : QMainWindow(parent){
setupUi(this);
scene=new QGraphicsScene;
QPixmap image(//path..);
QGraphicsPixmapItem mypixmap(image);
scene->addItem(&mypixmap);
graphicsView->setScene(scene);
graphicsView->show();
scene->setBackgroundBrush(image);
mypixmap.show();






graphicsView->setHorizontalScrollBarPolicy (Qt::ScrollBarAlwaysOff);
graphicsView->setVerticalScrollBarPolicy (Qt::ScrollBarAlwaysOff);



connect(actionZoom_in,SIGNAL(triggered()),this,SLO T(ZoomIn()));
connect(actionZoom_out,SIGNAL(triggered()),this,SL OT(ZoomOut()));
connect(actionPan_right,SIGNAL(triggered()),this,S LOT(Right()));
connect(actionPan_left,SIGNAL(triggered()),this,SL OT(Left()));
connect(actionPan_up,SIGNAL(triggered()),this,SLOT (Up()));
connect(actionPan_down,SIGNAL(triggered()),this,SL OT(Down()));



}

void gpsinterface::ZoomIn(){

graphicsView->scale(1.2,1.2);

}
void gpsinterface::ZoomOut(){

graphicsView->scale(1/1.2,1/1.2);

}
void gpsinterface::Right(){

graphicsView->translate(1.5,0);
}
void gpsinterface::Left(){
graphicsView->translate(-1.5,0);
}
void gpsinterface::Up(){
graphicsView->translate(0,1.5);
}
void gpsinterface::Down(){
graphicsView->translate(0,-1.5);
}
....

aamer4yu
5th April 2008, 16:00
You are setting the background brush as image, and also adding the image as an item.
Now arent there 2 images on top of each other. When you translate, will the background also move ??
May be this is causing problem. Try changing the background brush and see if it works fine.

peace_comp
7th April 2008, 10:59
I set off the bacgkround..but still the same problem ..no changing.. I wonder if there is another way to do it whithout callin' translate() !!!