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. QWidget expanding in QGraphicsScene/View

QWidget expanding in QGraphicsScene/View

Scheduled Pinned Locked Moved General and Desktop
6 Posts 3 Posters 3.5k 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.
  • BlackMambaB Offline
    BlackMambaB Offline
    BlackMamba
    wrote on last edited by
    #1

    Hello,

    Here is my issue.
    I have a CustomWidget class which inherits from QWidget and has a UI file. This widget's main layout has its policy to x expanding, y expanding.

    I want this widget to fit in a QGraphicsView by taking all the space available by the view (horizontally and vertically)
    For that, I created a QGraphicsScene, then used fitInView form the view.
    Then used scene->addWidget(customwidget)

    The CustomWidget is centered in the view but doesnt fit it. Also, the widget's global dimensions in the view are the same as the ones in the CustomWidget's UI file , which means no automatic expansion ...

    Cant figure out what's happening here :(

    Cheers,

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      just resize your widget/graphicsproxywidget everytime the QGraphicsView resizes to the sceneRect().

      Or play around with QGraphicsLayouts (not sure if there is one which does what you want though):
      @
      QGraphicsScene* scene;
      QGraphicsWidget *widget = scene->addWidget(new QWidget);

      QGraphicsLinearLayout *layout = new QGraphicsLinearLayout;
      layout->addItem(widget);

      QGraphicsWidget *form = new QGraphicsWidget;
      form->setLayout(layout);
      scene->addItem(form);
      @

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • BlackMambaB Offline
        BlackMambaB Offline
        BlackMamba
        wrote on last edited by
        #3

        I will try this out :) Thanks.
        By the way, is there a difference in this case between QGraphicsproxywidget or Widget (when adding it to the scene) ?

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          QGraphicsProxyWidget derives from QGraphicsWidget

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • N Offline
            N Offline
            NicuPopescu
            wrote on last edited by
            #5

            bq. just resize your widget/graphicsproxywidget everytime the QGraphicsView resizes to the sceneRect().

            ...or set the sceneRect to QGraphicsView's geometry and widget/graphicsproxywidget accordingly?

            1 Reply Last reply
            0
            • BlackMambaB Offline
              BlackMambaB Offline
              BlackMamba
              wrote on last edited by
              #6

              Indeed I think my issue was the scene->addWidget(customwidget) and not the scene which doesnt fit the view.
              scene->addWidget(customwidget) might set the widget's position by default to the center of the scene and not at 0,0. What do you think?

              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