Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Struggling with QGraphicsView

Struggling with QGraphicsView

Scheduled Pinned Locked Moved Unsolved General and Desktop
1 Posts 1 Posters 129 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HB76
    wrote on last edited by
    #1

    Hello there,

    I'm having hard time using QGraphicsView to display images.

    First, when I display an image for the first time, the image look very small despite the fact that I ask my view to fit the whole image.
    In fact, I tried to display the QGraphicsView size by calling qDebug and it appeared that my QGraphicsView size was 28x28 after startup and first display, and after a second display it has been updated to the good size (wich was 800x800).

    Also, I created two QPushButton to zoom in and out and I connected them with a slot that set the view scale. But when I click on the button, the view actually change but with one or more clicks of delay (not always the same).

    Here is my code :

    // CONSTRUCTOR
    scene = new QGraphicsScene(this);
    view = new GraphicsView(scene,this);
    zoom_factor = 1;
    
    ...
    
    // DRAWING SLOT
    QImage image(file);
    transformedScene->setSceneRect(image.rect());
    transformedScene->addPixmap(QPixmap::fromImage(image));
    transformedImageContainer->fitInView(scene-sceneRect(),Qt::AspectRatioMode::KeepAspectRatio);
    
    ...
    
    // ZOOM IN AND OUT SLOTS
    void window::zoomIn()
    {
        zoom_factor *= 1.25;
        view->scale(zoom_factor, zoom_factor);
        view->update();
    }
    
    void PreProcessScene::zoomOut()
    {
         zoom_factor *= 0.8;
         view->scale(zoom_factor, zoom_factor);
         view->update();
    }
    

    Do you know why do I get this strange behavior ?

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved