[SOLVED] zoom to fit in QGraphicsView
-
I have managed to fit my scene to QGraphicsView by using these:
@Canvas::Canvas(): QGraphicsScene(0,0,214,256)
{
}@and
@ if (!pixmapItem) {QPixmap tmpmap (QPixmap(fileName, 0, Qt::AutoColor)); pixmapItem = scene->addPixmap ( tmpmap.scaled (214,256) ); ui->graphicsView_inputImage->setScene(scene); } else {
QPixmap tmpmap (QPixmap(fileName, 0, Qt::AutoColor));
pixmapItem->setPixmap(tmpmap.scaled (214,256));
}@But still I have the problem of the real coordinates. Now in x coordiantes I am taking these (0,214) and in y coordinates I am taking these (-100,100).Could you explain how to do the mapToScene? What I should write as a press mouse event instead of these?
@void MainWindow::mousejustpressed(int x,int y)
{
int k1=size_y-y;unsigned char value;
QImage image(scene->sceneRect().size().toSize(), QImage::Format_RGB32); QPainter painter(&image); scene->render(&painter); value=image.pixel(x,k1);
}@
-
@Canvas::Canvas(): QGraphicsScene(0,0,100,100)
{
}
@@QPixmap tmpmap (fileName, 0, Qt::AutoColor);
if (!pixmapItem) {
pixmapItem = scene->addPixmap (tmpmap);
ui->graphicsView_inputImage->setScene(scene);
ui->graphicsView_inputImage->scale(ui->graphicsView_inputImage->width()/scene->width(),
ui->graphicsView_inputImage ->height()/scene->height());
} else {
pixmapItem->setPixmap(tmpmap);
}@@ void MainWindow::mousejustpressed(int x,int y)
{unsigned char value; QImage image(scene->sceneRect().size().toSize(), QImage::Format_RGB32); QPainter painter(&image); scene->render(&painter); value=image.pixel(ui->graphicsView_inputImage->mapToScene(x,y)); }
@
-
-
Sorry I forgot the toPoint():
@
void MainWindow::mousejustpressed(int x,int y)
{unsigned char value;
QImage image(scene->sceneRect().size().toSize(), QImage::Format_RGB32); QPainter painter(&image); scene->render(&painter); value=image.pixel(ui->graphicsView_inputImage->mapToScene(x,y).toPoint());
}@
Hope that helps! -
Thanks for the question and the input. I definitely got something from this thread :)