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. How to let the QGraphicsView centered on the QWidget?
QtWS25 Last Chance

How to let the QGraphicsView centered on the QWidget?

Scheduled Pinned Locked Moved General and Desktop
qt4.8
5 Posts 2 Posters 1.8k 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.
  • Vincent_XuV Offline
    Vincent_XuV Offline
    Vincent_Xu
    wrote on last edited by
    #1

    How to let the QGraphicsView centered on the QWidget?

    1 Reply Last reply
    0
    • JeroentjehomeJ Offline
      JeroentjehomeJ Offline
      Jeroentjehome
      wrote on last edited by
      #2

      Hi,
      Does the QGraphicsView have a fixed size?
      On your parent layout add horizontal and vertical spaces in a gridlayout.

      Greetz, Jeroen

      Vincent_XuV 1 Reply Last reply
      0
      • JeroentjehomeJ Jeroentjehome

        Hi,
        Does the QGraphicsView have a fixed size?
        On your parent layout add horizontal and vertical spaces in a gridlayout.

        Vincent_XuV Offline
        Vincent_XuV Offline
        Vincent_Xu
        wrote on last edited by
        #3

        @Jeroentjehome The size of QGraphicsView may be changed by user. I want to let the QGraphicsView constantly centered on whenever user resize the widget.
        Do you mean that I should add gridlayout in QWidget?

        1 Reply Last reply
        0
        • JeroentjehomeJ Offline
          JeroentjehomeJ Offline
          Jeroentjehome
          wrote on last edited by
          #4

          Hi, in QtWidgets programs it are always the layouts that set the resize policies for the children widgets. Setting a parent for an QWidget will not do anything for the behavior of resizing. Only when a layout is set and the QGraphicsView is inserted into that layout will it behave according the layouts resize commands. In this case a QWidget as parent where the layout is set on. In your case is a full fit of the parent widget not what you need? So in your case, create a QMainWindow (or some other form or QDialog etc) and place a layout on that widget. Then place the QGraphicsView into that layout and tadaaaa, it is always full widget sized in your parent widget.
          You might want to read up on the QLayout examples etc. That will explain a lot!

          Greetz, Jeroen

          Vincent_XuV 1 Reply Last reply
          0
          • JeroentjehomeJ Jeroentjehome

            Hi, in QtWidgets programs it are always the layouts that set the resize policies for the children widgets. Setting a parent for an QWidget will not do anything for the behavior of resizing. Only when a layout is set and the QGraphicsView is inserted into that layout will it behave according the layouts resize commands. In this case a QWidget as parent where the layout is set on. In your case is a full fit of the parent widget not what you need? So in your case, create a QMainWindow (or some other form or QDialog etc) and place a layout on that widget. Then place the QGraphicsView into that layout and tadaaaa, it is always full widget sized in your parent widget.
            You might want to read up on the QLayout examples etc. That will explain a lot!

            Vincent_XuV Offline
            Vincent_XuV Offline
            Vincent_Xu
            wrote on last edited by
            #5

            @Jeroentjehome Thank you, I'll try it

            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