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. Qt creator: Widget [SOLVED]
Qt 6.11 is out! See what's new in the release blog

Qt creator: Widget [SOLVED]

Scheduled Pinned Locked Moved General and Desktop
9 Posts 4 Posters 3.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.
  • B Offline
    B Offline
    blackbelt
    wrote on last edited by
    #1

    Is there the possibility to specify the dimesion of a QWidget to be something like the 80% of the size of the parent?

    1 Reply Last reply
    0
    • R Offline
      R Offline
      raaghuu
      wrote on last edited by
      #2

      There are QWidget properties that can be used here -> size, height, width. So you could do something like
      @
      myWidget -> setSize( QSize( (parentWidget->height() * 4 / 5), (parentWidget->width() * 4 / 5) ) )
      @

      1 Reply Last reply
      0
      • M Offline
        M Offline
        moritzg
        wrote on last edited by
        #3

        The "easy" solution would be to just get the size of the parent - using getSize() or width(),height() member fns - and set the size of your widget to be 80% of that. Something like this:
        @
        QWidget* parent = new QWidget();
        QWidget* myWidget = new QWidget(parent);
        myWidget->setFixedSize(parent->width()*0.8, parent->height()*0.8);@

        If your parent widget is resizable, you may need to subclass QWidget for your child widget and reimplement resizeEvent().

        EDIT: myWidget->resize() is probably better than myWidget->setFixedSize().

        1 Reply Last reply
        0
        • B Offline
          B Offline
          blackbelt
          wrote on last edited by
          #4

          ok, thank you. How can I add a QWidget to a QGraphicsView?

          1 Reply Last reply
          0
          • M Offline
            M Offline
            moritzg
            wrote on last edited by
            #5

            You probably need to add it to the corresponding QGraphicsScene of the QGraphicsView, using e.g. @ QGraphicsScene::addWidget(myWidget) @

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #6

              Adding widgets to grahpics views, although possible, is probably not a good idea. It never worked all that well...

              1 Reply Last reply
              0
              • B Offline
                B Offline
                blackbelt
                wrote on last edited by
                #7

                So where can I add it ? To the QGraphicsScene?

                Thank you

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #8

                  No, I meant using widgets in the QGraphicsView framework (including *Scene) should be avoided if possible. It may work for you, but chances are you'll run into gliches and/or performance issues.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    blackbelt
                    wrote on last edited by
                    #9

                    It is true. I am experimenting permformance issue. So where should I add it?

                    ty

                    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