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 create "float" elements?
Forum Update on Monday, May 27th 2025

How to create "float" elements?

Scheduled Pinned Locked Moved Unsolved General and Desktop
7 Posts 4 Posters 2.2k 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.
  • R Offline
    R Offline
    rock wang
    wrote on 9 Jul 2018, 05:03 last edited by
    #1

    I want place a QGraphicsView fullfill the window, and some buttons "overlay" it. How to layout them?
    I found that no matter what layout I use, these buttons "beside" the QGraphicsView other than "float" above it, unless I set the QGraphicsView's size equal to window's size. But when my user adjust the window's size at run time, The QGraphicsView's size will not change follow the window size.
    0_1531112366915_29f0010f-887e-48fc-bce6-20f4a22b7734-image.png

    J V 2 Replies Last reply 9 Jul 2018, 05:57
    0
    • R rock wang
      9 Jul 2018, 05:03

      I want place a QGraphicsView fullfill the window, and some buttons "overlay" it. How to layout them?
      I found that no matter what layout I use, these buttons "beside" the QGraphicsView other than "float" above it, unless I set the QGraphicsView's size equal to window's size. But when my user adjust the window's size at run time, The QGraphicsView's size will not change follow the window size.
      0_1531112366915_29f0010f-887e-48fc-bce6-20f4a22b7734-image.png

      J Offline
      J Offline
      jsulm
      Lifetime Qt Champion
      wrote on 9 Jul 2018, 05:57 last edited by jsulm 7 Sept 2018, 05:58
      #2

      @rock-wang You don't have any layout. Select both QGraphicsView and the button and then press on "Layout in a Grid" button.
      And you should read http://doc.qt.io/qt-5/layout.html

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • R Offline
        R Offline
        rock wang
        wrote on 9 Jul 2018, 06:53 last edited by
        #3

        @jsulm said in How to create "float" elements?:

        u don't hav
        I modified my UI
        0_1531118987034_2a7e2d5f-fe5c-49b6-8d10-6752a61620ca-image.png

        <?xml version="1.0" encoding="UTF-8"?>
        <ui version="4.0">
         <class>MainWindow</class>
         <widget class="QMainWindow" name="MainWindow">
          <property name="geometry">
           <rect>
            <x>0</x>
            <y>0</y>
            <width>810</width>
            <height>526</height>
           </rect>
          </property>
          <property name="windowTitle">
           <string>MainWindow</string>
          </property>
          <widget class="QWidget" name="centralWidget">
           <layout class="QGridLayout" name="gridLayout">
            <item row="0" column="0">
             <widget class="QGraphicsView" name="graphicsView"/>
            </item>
            <item row="0" column="1">
             <widget class="QGroupBox" name="buttonGroup">
              <property name="sizePolicy">
               <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
                <horstretch>0</horstretch>
                <verstretch>0</verstretch>
               </sizepolicy>
              </property>
              <layout class="QVBoxLayout" name="verticalLayout">
               <item>
                <widget class="QPushButton" name="button1">
                 <property name="text">
                  <string>Button1</string>
                 </property>
                </widget>
               </item>
               <item>
                <widget class="QPushButton" name="Button2">
                 <property name="text">
                  <string>Button2</string>
                 </property>
                </widget>
               </item>
               <item>
                <widget class="QPushButton" name="pushButton_3">
                 <property name="text">
                  <string>Button3</string>
                 </property>
                </widget>
               </item>
               <item>
                <widget class="QPushButton" name="pushButton_6">
                 <property name="text">
                  <string>Button4</string>
                 </property>
                </widget>
               </item>
               <item>
                <widget class="QPushButton" name="pushButton_4">
                 <property name="text">
                  <string>Button5</string>
                 </property>
                </widget>
               </item>
               <item>
                <widget class="QPushButton" name="pushButton_5">
                 <property name="text">
                  <string>Button6</string>
                 </property>
                </widget>
               </item>
               <item>
                <widget class="QPushButton" name="pushButton_9">
                 <property name="text">
                  <string>Button7</string>
                 </property>
                </widget>
               </item>
               <item>
                <widget class="QPushButton" name="pushButton_7">
                 <property name="text">
                  <string>Button8</string>
                 </property>
                </widget>
               </item>
               <item>
                <widget class="QPushButton" name="pushButton_8">
                 <property name="text">
                  <string>Button9</string>
                 </property>
                </widget>
               </item>
               <item>
                <widget class="QPushButton" name="pushButton_10">
                 <property name="text">
                  <string>Button10</string>
                 </property>
                </widget>
               </item>
              </layout>
             </widget>
            </item>
           </layout>
          </widget>
         </widget>
         <layoutdefault spacing="6" margin="0"/>
         <resources/>
         <connections/>
        </ui>
        
        

        What I expected is this
        0_1531119179828_29dbc99a-68ac-4c22-9a79-f64e5c026cfd-image.png

        1 Reply Last reply
        0
        • R rock wang
          9 Jul 2018, 05:03

          I want place a QGraphicsView fullfill the window, and some buttons "overlay" it. How to layout them?
          I found that no matter what layout I use, these buttons "beside" the QGraphicsView other than "float" above it, unless I set the QGraphicsView's size equal to window's size. But when my user adjust the window's size at run time, The QGraphicsView's size will not change follow the window size.
          0_1531112366915_29f0010f-887e-48fc-bce6-20f4a22b7734-image.png

          V Offline
          V Offline
          VRonin
          wrote on 9 Jul 2018, 07:36 last edited by
          #4

          @rock-wang said in How to create "float" elements?:

          The QGraphicsView's size will not change follow the window size.

          Just reimplement resizeEvent and resize the QGraphicsView

          "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
          ~Napoleon Bonaparte

          On a crusade to banish setIndexWidget() from the holy land of Qt

          R 1 Reply Last reply 9 Jul 2018, 08:31
          0
          • V VRonin
            9 Jul 2018, 07:36

            @rock-wang said in How to create "float" elements?:

            The QGraphicsView's size will not change follow the window size.

            Just reimplement resizeEvent and resize the QGraphicsView

            R Offline
            R Offline
            rock wang
            wrote on 9 Jul 2018, 08:31 last edited by
            #5

            @VRonin said in How to create "float" elements?:

            Just reimplement resizeEvent and resize the QGraphicsView

            Any other solutions?For example the layout.

            1 Reply Last reply
            0
            • V Offline
              V Offline
              VRonin
              wrote on 9 Jul 2018, 08:35 last edited by VRonin 7 Sept 2018, 08:39
              #6

              Nope, there's no layout that puts stuff on top of each other. The resizeEvent solution, however, should be just a couple of lines of code...

              void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE{
              ui->graphicsView->resize(size());
              QWidget::resizeEvent(event);
              }
              

              "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
              ~Napoleon Bonaparte

              On a crusade to banish setIndexWidget() from the holy land of Qt

              J.HilkJ 1 Reply Last reply 9 Jul 2018, 08:38
              0
              • V VRonin
                9 Jul 2018, 08:35

                Nope, there's no layout that puts stuff on top of each other. The resizeEvent solution, however, should be just a couple of lines of code...

                void resizeEvent(QResizeEvent *event) Q_DECL_OVERRIDE{
                ui->graphicsView->resize(size());
                QWidget::resizeEvent(event);
                }
                
                J.HilkJ Offline
                J.HilkJ Offline
                J.Hilk
                Moderators
                wrote on 9 Jul 2018, 08:38 last edited by
                #7

                @VRonin said in How to create "float" elements?:

                Nope, ther's no layout that puts stuff on top of each other.

                Actually, iirc, you can trick the QGridlayout. It's not possible with the desginer, but you can asign multiple objects to the same cell via code. Those are placed on top of each other and the size of each object is managed via the Layout.


                Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                Q: What's that?
                A: It's blue light.
                Q: What does it do?
                A: It turns blue.

                1 Reply Last reply
                1

                1/7

                9 Jul 2018, 05:03

                • Login

                • Login or register to search.
                1 out of 7
                • First post
                  1/7
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved