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. [SOLVED] Resize QGraphicsItem when window resizes
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] Resize QGraphicsItem when window resizes

Scheduled Pinned Locked Moved General and Desktop
3 Posts 2 Posters 2.0k Views 1 Watching
  • 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.
  • guidupasG Offline
    guidupasG Offline
    guidupas
    wrote on last edited by
    #1

    Hello all!

    I am trying to resize a QGraphicsItem when I resize the app window but its not working.
    How could I do that?
    @
    //Tool Box 3
    QGridLayout *gridLayoutInvestimento5 = new QGridLayout(boxInvestimento3);
    QGraphicsView *graphicsViewFluxoCaixa = new QGraphicsView(boxInvestimento3);
    QGraphicsScene *graphicsSceneFluxoCaixa = new QGraphicsScene(graphicsViewFluxoCaixa);
    graphicsViewFluxoCaixa->setScene(graphicsSceneFluxoCaixa);

    boxInvestimento3->setLayout(gridLayoutInvestimento5);
    gridLayoutInvestimento5->addWidget(graphicsViewFluxoCaixa);
    
    //graphicsViewFluxoCaixa->adjustSize();
    
    //graphicsViewFluxoCaixa->setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding);
    
    //graphicsViewFluxoCaixa->fitInView(graphicsSceneFluxoCaixa->itemsBoundingRect(), Qt::IgnoreAspectRatio);
    
    QPen caneta(Qt::black);
    caneta.setWidth(4);
    QGraphicsLineItem *linhaTempo = new QGraphicsLineItem(0,0,graphicsViewFluxoCaixa->width(),0);
    
    linhaTempo->setPen(caneta);
    graphicsSceneFluxoCaixa->addItem(linhaTempo);
    graphicsViewFluxoCaixa->adjustSize();
    graphicsViewFluxoCaixa->setBackgroundBrush(QBrush(Qt::red));
    

    @

    Thanks a lot.

    Att.
    Guilherme Cortada Dupas

    1 Reply Last reply
    0
    • A Offline
      A Offline
      Asperamanca
      wrote on last edited by
      #2

      The GraphicsView framework separates the scene composition from the view(s) where it is displayed. So you try to work against a basic design principle, which is always hard.

      Not impossible, of course.

      First, you have to register changes to the QGraphicsView. You can do this by subclassing QGraphicsView and handling the resizeEvent.
      Now, you basically have two options:

      1. Maybe all you want is zoom and scroll so the item is e.g. centered in the view (you were not very specific about what you want to do). In this case, all you need is to use QGraphicsView's scroll and zoom methods to get what you want (e.g. fitInView)
      2. If for some reason you really need to resize the actual QGraphicsItem, you can do it from there. But I need to point out that this has big disadvantages - think about what would happen if you had two QGraphicsViews connected to the same scene!
      1 Reply Last reply
      0
      • guidupasG Offline
        guidupasG Offline
        guidupas
        wrote on last edited by
        #3

        Thank you very much.

        I subclassed QGRaphicsView, and its is working.

        Att.
        Guilherme Cortada Dupas

        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