QT中可调整大小的窗口

时间:2018-09-22 09:32:29

标签: qt user-interface

我正在接受有关QT的旧在线培训,培训师的接缝不再可及,因此也许有人可以启发我,在此培训中,制作了一个小的图形窗口来绘制图形。有一个用于按钮的区域(用于选择形状)和一个用于绘制的区域。现在,在此过程中,他可以调整主窗体的大小,并且当他执行此操作时,可以使用该窗体调整这些区域的大小。我完全按照课程学习,但是由于我没有这种行为,因此本课程中缺少某些内容。我想知道如何使用QTcreator(v4.71)来获得这种行为,

我在下面包含.ui文件的代码:

<?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>417</width>
<height>440</height>
</rect>
</property>
<property name="windowTitle">
<string>Main Window</string>
</property>
<widget class="QWidget" name="centralWidget">
<widget class="QWidget" name="">
<property name="geometry">
 <rect>
  <x>20</x>
  <y>30</y>
  <width>381</width>
  <height>381</height>
  </rect>
  </property>
  <layout class="QHBoxLayout" name="horizontalLayout">
  <item>
  <widget class="RenderArea" name="renderArea" native="true">
   <property name="sizePolicy">
    <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
     <horstretch>0</horstretch>
     <verstretch>0</verstretch>
    </sizepolicy>
    </property>
    <layout class="QGridLayout" name="gridLayout">
    <item row="0" column="0">
     <spacer name="horizontalSpacer">
      <property name="orientation">
       <enum>Qt::Horizontal</enum>
      </property>
      <property name="sizeHint" stdset="0">
       <size>
        <width>40</width>
        <height>20</height>
       </size>
      </property>
      </spacer>
      </item>
      <item row="0" column="1">
      <layout class="QVBoxLayout" name="verticalLayout">
      <item>
       <widget class="QPushButton" name="btnAstroid">
        <property name="text">
         <string>Astroid</string>
        </property>
       </widget>
      </item>
      <item>
       <widget class="QPushButton" name="btnCycloid">
        <property name="text">
         <string>Cycloid</string>
        </property>
       </widget>
      </item>
      <item>
       <widget class="QPushButton" name="btnHuygens">
        <property name="text">
         <string>Huygens</string>
        </property>
       </widget>
      </item>
      <item>
       <widget class="QPushButton" name="btnHypo">
        <property name="text">
         <string>Hypo Cycloid</string>
        </property>
       </widget>
      </item>
      <item>
       <spacer name="verticalSpacer">
        <property name="orientation">
         <enum>Qt::Vertical</enum>
        </property>
        <property name="sizeHint" stdset="0">
         <size>
          <width>20</width>
          <height>40</height>
         </size>
        </property>
       </spacer>
      </item>
     </layout>
    </item>
    </layout>
    </widget>
    </item>
    </layout>
    </widget>
   </widget>
  <widget class="QStatusBar" name="statusBar"/>
  </widget>
  <layoutdefault spacing="6" margin="11"/>
  <customwidgets>
   <customwidget>
   <class>RenderArea</class>
   <extends>QWidget</extends>
   <header>renderarea.h</header>
   <container>1</container>
   </customwidget>
  </customwidgets>
  <resources/>
  <connections/>
 </ui>

1 个答案:

答案 0 :(得分:1)

通过在主表单中添加网格属性来解决。 选择ctrl + g时,顶部的小图标 如How to expand widgets with window resize?

相关问题