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] link GraphicsSceneItem size to GraphicsView size
Forum Updated to NodeBB v4.3 + New Features

[solved] link GraphicsSceneItem size to GraphicsView size

Scheduled Pinned Locked Moved General and Desktop
link sizeqgraphicssceneiqgraphicsview
5 Posts 2 Posters 1.8k 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.
  • QT-static-prgmQ Offline
    QT-static-prgmQ Offline
    QT-static-prgm
    wrote on last edited by QT-static-prgm
    #1

    Hi,

    i want to link the size of some QGraphicsSceneItems to the QGraphicsView where they are displayed.
    Example:
    There are X (e.g. 3) rectangles on the GraphicsView and the GraphicsView has the width Y (e.g. 90).
    I want the rectangles to have the size Y/X (=10).

    Easy right? But i want it to be updated everytime there cames a new Rectangle and when the View size changes.
    Example:
    Button press generates an new rectangle, so now the size of each rectangle needs to be 90/4 = 22,5
    And when the User changes the size of the Window, the size of the View will change, too. So lets say the View is now 100 width, and the rectangles need to be 25 width now.

    Someone an idea how to do this??

    1 Reply Last reply
    0
    • V Offline
      V Offline
      Vitek
      wrote on last edited by
      #2

      Create a signal in Inheritance of QGraphicsView, and emit its when it is resizing. After connet the singnal with GraphicsSceneItem.

      1 Reply Last reply
      0
      • QT-static-prgmQ Offline
        QT-static-prgmQ Offline
        QT-static-prgm
        wrote on last edited by QT-static-prgm
        #3

        How do you mean that. Do you mean to make an new class, inherit from QGraphicsView and than reimplement void QWidget::resizeEvent to resize the objects, or is there an other way where i don't need a new class??

        ==EDIT==

        I solved it with an custom resize event.

        void MainWindow::resizeEvent(QResizeEvent *event)
        {
        QMainWindow::resizeEvent(event);

        if (anzObjekte == 0)
        	return;
        int widthGesamt = ui->graphicsView->size().width();
        int x(0);
        int breite = (widthGesamt - 10) / anzObjekte;
        
        for(QVector<QGraphicsRectItem*>::iterator it = list.begin(); it != list.end(); it++)
        {
        	(*it)->setRect(x, 0, breite, 40);
        	x += breite;
        }
        

        }

        But now there is the scrollbar still left if you make the window smaller. The objects are all resized correctly, but the scrollbar is still there. How can i remove it??

        1 Reply Last reply
        0
        • V Offline
          V Offline
          Vitek
          wrote on last edited by
          #4

          Yes, you can use it

          view.setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
          view.setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
          
          1 Reply Last reply
          0
          • QT-static-prgmQ Offline
            QT-static-prgmQ Offline
            QT-static-prgm
            wrote on last edited by
            #5

            Thank you. That solved it :D
            I need to set a fix scene rect for the view, because it always move the rectangle to the left boarder when i changed the size, but now everything is working :D

            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