RError.com

RError.com Logo RError.com Logo

RError.com Navigation

  • 主页

Mobile menu

Close
  • 主页
  • 系统&网络
    • 热门问题
    • 最新问题
    • 标签
  • Ubuntu
    • 热门问题
    • 最新问题
    • 标签
  • 帮助
主页 / 问题 / 1587866
Accepted
Никита Пфейфер
Никита Пфейфер
Asked:2024-07-21 20:59:21 +0000 UTC2024-07-21 20:59:21 +0000 UTC 2024-07-21 20:59:21 +0000 UTC

Qt Desginer 表单中的静态按钮未显示,因为我需要它们

  • 772

我在Qt Desginer中制作了一个带有小部件布局的程序,一切正常。

但每当我尝试做类似的事情时,它就不起作用。
那些。在工作版本中,按钮是静态的,具体取决于程序扩展,例如:

在此输入图像描述

在此输入图像描述

您可能会注意到按钮始终保持相同的大小。

不幸的是,无论我多么努力,我都无法达到相同的结果,我检查了我拥有的所有设置,但我做不到。



下面是它现在如何工作的示例:

在此输入图像描述

在此输入图像描述

请帮助我,我缺少什么?

工作.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>433</width>
    <height>576</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <property name="styleSheet">
    <string notr="true">#centralwidget{background-color: rgb(17, 18, 21);}</string>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item alignment="Qt::AlignHCenter">
     <widget class="QWidget" name="widget" native="true">
      <property name="minimumSize">
       <size>
        <width>165</width>
        <height>38</height>
       </size>
      </property>
      <property name="maximumSize">
       <size>
        <width>16777215</width>
        <height>16777215</height>
       </size>
      </property>
      <property name="styleSheet">
       <string notr="true">background-color: rgb(17, 18, 21);</string>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout_2">
       <item>
        <widget class="QLabel" name="label">
         <property name="font">
          <font>
           <weight>75</weight>
           <bold>true</bold>
          </font>
         </property>
         <property name="styleSheet">
          <string notr="true">color: rgb(151, 102, 255);</string>
         </property>
         <property name="text">
          <string>Конвертация YML в JSON</string>
         </property>
         <property name="alignment">
          <set>Qt::AlignCenter</set>
         </property>
        </widget>
       </item>
      </layout>
     </widget>
    </item>
    <item>
     <widget class="QWidget" name="widget_2" native="true">
      <property name="minimumSize">
       <size>
        <width>421</width>
        <height>104</height>
       </size>
      </property>
      <property name="maximumSize">
       <size>
        <width>16777215</width>
        <height>16777215</height>
       </size>
      </property>
      <property name="styleSheet">
       <string notr="true">background-color: rgb(23, 25, 33);</string>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout_3">
       <item>
        <widget class="Line" name="line">
         <property name="styleSheet">
          <string notr="true">background-color: rgb(151, 102, 255);</string>
         </property>
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>
        </widget>
       </item>
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout">
         <item>
          <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>
          <widget class="QLabel" name="label_2">
           <property name="minimumSize">
            <size>
             <width>61</width>
             <height>60</height>
            </size>
           </property>
           <property name="maximumSize">
            <size>
             <width>61</width>
             <height>60</height>
            </size>
           </property>
           <property name="styleSheet">
            <string notr="true">background-image: url(:/file/images/yml3.png);</string>
           </property>
           <property name="text">
            <string/>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QLineEdit" name="lineEdit_3">
           <property name="minimumSize">
            <size>
             <width>271</width>
             <height>31</height>
            </size>
           </property>
           <property name="maximumSize">
            <size>
             <width>291</width>
             <height>16777215</height>
            </size>
           </property>
           <property name="styleSheet">
            <string notr="true">background-color: rgb(66, 71, 90);
color: rgb(162, 162, 162);
border-radius: 15px; /* Задайте радиус, чтобы сделать края овальными */
padding: 2px;</string>
           </property>
           <property name="cursorPosition">
            <number>0</number>
           </property>
           <property name="alignment">
            <set>Qt::AlignCenter</set>
           </property>
           <property name="placeholderText">
            <string>Название файла.yml</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QLabel" name="label_3">
           <property name="minimumSize">
            <size>
             <width>61</width>
             <height>60</height>
            </size>
           </property>
           <property name="maximumSize">
            <size>
             <width>61</width>
             <height>60</height>
            </size>
           </property>
           <property name="styleSheet">
            <string notr="true">background-image: url(:/file/images/json3.png);</string>
           </property>
           <property name="text">
            <string/>
           </property>
          </widget>
         </item>
         <item>
          <spacer name="horizontalSpacer_2">
           <property name="orientation">
            <enum>Qt::Horizontal</enum>
           </property>
           <property name="sizeHint" stdset="0">
            <size>
             <width>40</width>
             <height>20</height>
            </size>
           </property>
          </spacer>
         </item>
        </layout>
       </item>
       <item>
        <widget class="Line" name="line_2">
         <property name="styleSheet">
          <string notr="true">background-color: rgb(151, 102, 255);</string>
         </property>
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>
        </widget>
       </item>
      </layout>
     </widget>
    </item>
    <item alignment="Qt::AlignHCenter">
     <widget class="QWidget" name="widget_3" native="true">
      <property name="minimumSize">
       <size>
        <width>0</width>
        <height>414</height>
       </size>
      </property>
      <property name="styleSheet">
       <string notr="true">background-color: rgb(17, 18, 21);</string>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout_5">
       <item>
        <layout class="QVBoxLayout" name="verticalLayout_4">
         <property name="spacing">
          <number>13</number>
         </property>
         <property name="topMargin">
          <number>0</number>
         </property>
         <property name="bottomMargin">
          <number>0</number>
         </property>
         <item>
          <widget class="QPushButton" name="addFile">
           <property name="minimumSize">
            <size>
             <width>211</width>
             <height>31</height>
            </size>
           </property>
           <property name="font">
            <font>
             <weight>75</weight>
             <bold>true</bold>
            </font>
           </property>
           <property name="styleSheet">
            <string notr="true">#addFile {
    background-color: rgb(151, 102, 255);
/*background-color: rgb(0, 139, 247);*/
    color: rgb(255, 255, 255);
border-radius: 15px; /* Задайте радиус, чтобы сделать края овальными */
padding: 2px;}


#addFile:hover{
background-color: rgb(164, 205, 217);
}</string>
           </property>
           <property name="text">
            <string>Выбрать файл</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QPushButton" name="convert">
           <property name="minimumSize">
            <size>
             <width>211</width>
             <height>31</height>
            </size>
           </property>
           <property name="font">
            <font>
             <weight>75</weight>
             <bold>true</bold>
            </font>
           </property>
           <property name="styleSheet">
            <string notr="true">#convert {
background-color: rgb(151, 102, 255);
/*background-color: rgb(0, 139, 247);*/
    color: rgb(255, 255, 255);
border-radius: 15px; /* Задайте радиус, чтобы сделать края овальными */
padding: 2px;}


#convert:hover{
background-color: rgb(164, 205, 217);
}</string>
           </property>
           <property name="text">
            <string>Конвертировать</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QPushButton" name="add">
           <property name="minimumSize">
            <size>
             <width>211</width>
             <height>31</height>
            </size>
           </property>
           <property name="font">
            <font>
             <weight>75</weight>
             <bold>true</bold>
            </font>
           </property>
           <property name="styleSheet">
            <string notr="true">#add {
background-color: rgb(151, 102, 255);
/*background-color: rgb(0, 139, 247);*/
    color: rgb(255, 255, 255);
border-radius: 15px; /* Задайте радиус, чтобы сделать края овальными */
padding: 2px;}


#add:hover{
background-color: rgb(164, 205, 217);
}</string>
           </property>
           <property name="text">
            <string>Добавить Json в Базу даных</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>
         <item alignment="Qt::AlignHCenter">
          <widget class="QLabel" name="label_4">
           <property name="minimumSize">
            <size>
             <width>200</width>
             <height>200</height>
            </size>
           </property>
           <property name="maximumSize">
            <size>
             <width>9999</width>
             <height>9999</height>
            </size>
           </property>
           <property name="styleSheet">
            <string notr="true">background-image: url(:/file/images/gnvclogo.png);</string>
           </property>
           <property name="text">
            <string/>
           </property>
          </widget>
         </item>
         <item>
          <spacer name="verticalSpacer_3">
           <property name="orientation">
            <enum>Qt::Vertical</enum>
           </property>
           <property name="sizeHint" stdset="0">
            <size>
             <width>20</width>
             <height>40</height>
            </size>
           </property>
          </spacer>
         </item>
         <item>
          <widget class="QPushButton" name="info">
           <property name="minimumSize">
            <size>
             <width>211</width>
             <height>31</height>
            </size>
           </property>
           <property name="font">
            <font>
             <weight>75</weight>
             <bold>true</bold>
            </font>
           </property>
           <property name="styleSheet">
            <string notr="true">#info {
background-color: rgb(151, 102, 255);
/*background-color: rgb(0, 139, 247);*/
    color: rgb(255, 255, 255);
border-radius: 15px; /* Задайте радиус, чтобы сделать края овальными */
padding: 2px;}


#info:hover{
background-color: rgb(164, 205, 217);
}</string>
           </property>
           <property name="text">
            <string>Дополнительная информация</string>
           </property>
          </widget>
         </item>
        </layout>
       </item>
      </layout>
     </widget>
    </item>
   </layout>
  </widget>
 </widget>
 <resources>
  <include location="../qrc_files/file.qrc"/>
 </resources>
 <connections/>
</ui>


不工作 .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>443</width>
    <height>592</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>MainWindow</string>
  </property>
  <widget class="QWidget" name="centralwidget">
   <property name="styleSheet">
    <string notr="true">#centralwidget{background-color: rgb(17, 18, 21);}</string>
   </property>
   <layout class="QVBoxLayout" name="verticalLayout">
    <item>
     <widget class="QWidget" name="widget" native="true">
      <property name="minimumSize">
       <size>
        <width>165</width>
        <height>38</height>
       </size>
      </property>
      <property name="maximumSize">
       <size>
        <width>16777215</width>
        <height>16777215</height>
       </size>
      </property>
      <property name="styleSheet">
       <string notr="true">background-color: rgb(17, 18, 21);</string>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout_2">
       <item>
        <widget class="QLabel" name="label">
         <property name="font">
          <font>
           <weight>75</weight>
           <bold>true</bold>
          </font>
         </property>
         <property name="styleSheet">
          <string notr="true">color: rgb(151, 102, 255);</string>
         </property>
         <property name="text">
          <string>Конвертация YML в JSON</string>
         </property>
         <property name="alignment">
          <set>Qt::AlignCenter</set>
         </property>
        </widget>
       </item>
      </layout>
     </widget>
    </item>
    <item>
     <widget class="QWidget" name="widget_2" native="true">
      <property name="minimumSize">
       <size>
        <width>421</width>
        <height>104</height>
       </size>
      </property>
      <property name="maximumSize">
       <size>
        <width>16777215</width>
        <height>16777215</height>
       </size>
      </property>
      <property name="styleSheet">
       <string notr="true">background-color: rgb(23, 25, 33);</string>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout_3">
       <item>
        <widget class="Line" name="line">
         <property name="styleSheet">
          <string notr="true">background-color: rgb(151, 102, 255);</string>
         </property>
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>
        </widget>
       </item>
       <item>
        <layout class="QHBoxLayout" name="horizontalLayout">
         <item>
          <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>
          <widget class="QLabel" name="label_2">
           <property name="minimumSize">
            <size>
             <width>61</width>
             <height>60</height>
            </size>
           </property>
           <property name="maximumSize">
            <size>
             <width>61</width>
             <height>60</height>
            </size>
           </property>
           <property name="styleSheet">
            <string notr="true">background-image: url(:/file/images/yml3.png);</string>
           </property>
           <property name="text">
            <string/>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QLineEdit" name="lineEdit_3">
           <property name="minimumSize">
            <size>
             <width>271</width>
             <height>31</height>
            </size>
           </property>
           <property name="maximumSize">
            <size>
             <width>291</width>
             <height>16777215</height>
            </size>
           </property>
           <property name="styleSheet">
            <string notr="true">background-color: rgb(66, 71, 90);
color: rgb(162, 162, 162);
border-radius: 15px; /* Задайте радиус, чтобы сделать края овальными */
padding: 2px;</string>
           </property>
           <property name="cursorPosition">
            <number>0</number>
           </property>
           <property name="alignment">
            <set>Qt::AlignCenter</set>
           </property>
           <property name="placeholderText">
            <string>Название файла.yml</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QLabel" name="label_3">
           <property name="minimumSize">
            <size>
             <width>61</width>
             <height>60</height>
            </size>
           </property>
           <property name="maximumSize">
            <size>
             <width>61</width>
             <height>60</height>
            </size>
           </property>
           <property name="styleSheet">
            <string notr="true">background-image: url(:/file/images/json3.png);</string>
           </property>
           <property name="text">
            <string/>
           </property>
          </widget>
         </item>
         <item>
          <spacer name="horizontalSpacer_2">
           <property name="orientation">
            <enum>Qt::Horizontal</enum>
           </property>
           <property name="sizeHint" stdset="0">
            <size>
             <width>40</width>
             <height>20</height>
            </size>
           </property>
          </spacer>
         </item>
        </layout>
       </item>
       <item>
        <widget class="Line" name="line_2">
         <property name="styleSheet">
          <string notr="true">background-color: rgb(151, 102, 255);</string>
         </property>
         <property name="orientation">
          <enum>Qt::Horizontal</enum>
         </property>
        </widget>
       </item>
      </layout>
     </widget>
    </item>
    <item>
     <widget class="QWidget" name="widget_3" native="true">
      <property name="minimumSize">
       <size>
        <width>0</width>
        <height>414</height>
       </size>
      </property>
      <property name="styleSheet">
       <string notr="true">background-color: rgb(17, 18, 21);</string>
      </property>
      <layout class="QVBoxLayout" name="verticalLayout_5">
       <item>
        <layout class="QVBoxLayout" name="verticalLayout_4">
         <property name="spacing">
          <number>13</number>
         </property>
         <property name="topMargin">
          <number>0</number>
         </property>
         <property name="bottomMargin">
          <number>0</number>
         </property>
         <item>
          <widget class="QPushButton" name="addFile">
           <property name="minimumSize">
            <size>
             <width>211</width>
             <height>31</height>
            </size>
           </property>
           <property name="font">
            <font>
             <weight>75</weight>
             <bold>true</bold>
            </font>
           </property>
           <property name="styleSheet">
            <string notr="true">#addFile {
    background-color: rgb(151, 102, 255);
/*background-color: rgb(0, 139, 247);*/
    color: rgb(255, 255, 255);
border-radius: 15px; /* Задайте радиус, чтобы сделать края овальными */
padding: 2px;}


#addFile:hover{
background-color: rgb(164, 205, 217);
}</string>
           </property>
           <property name="text">
            <string>Выбрать файл</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QPushButton" name="convert">
           <property name="minimumSize">
            <size>
             <width>211</width>
             <height>31</height>
            </size>
           </property>
           <property name="font">
            <font>
             <weight>75</weight>
             <bold>true</bold>
            </font>
           </property>
           <property name="styleSheet">
            <string notr="true">#convert {
background-color: rgb(151, 102, 255);
/*background-color: rgb(0, 139, 247);*/
    color: rgb(255, 255, 255);
border-radius: 15px; /* Задайте радиус, чтобы сделать края овальными */
padding: 2px;}


#convert:hover{
background-color: rgb(164, 205, 217);
}</string>
           </property>
           <property name="text">
            <string>Конвертировать</string>
           </property>
          </widget>
         </item>
         <item>
          <widget class="QPushButton" name="add">
           <property name="minimumSize">
            <size>
             <width>211</width>
             <height>31</height>
            </size>
           </property>
           <property name="font">
            <font>
             <weight>75</weight>
             <bold>true</bold>
            </font>
           </property>
           <property name="styleSheet">
            <string notr="true">#add {
background-color: rgb(151, 102, 255);
/*background-color: rgb(0, 139, 247);*/
    color: rgb(255, 255, 255);
border-radius: 15px; /* Задайте радиус, чтобы сделать края овальными */
padding: 2px;}


#add:hover{
background-color: rgb(164, 205, 217);
}</string>
           </property>
           <property name="text">
            <string>Добавить Json в Базу даных</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>
         <item>
          <widget class="QLabel" name="label_4">
           <property name="minimumSize">
            <size>
             <width>200</width>
             <height>200</height>
            </size>
           </property>
           <property name="maximumSize">
            <size>
             <width>9999</width>
             <height>9999</height>
            </size>
           </property>
           <property name="styleSheet">
            <string notr="true">background-image: url(:/file/images/gnvclogo.png);</string>
           </property>
           <property name="text">
            <string/>
           </property>
          </widget>
         </item>
         <item>
          <spacer name="verticalSpacer_3">
           <property name="orientation">
            <enum>Qt::Vertical</enum>
           </property>
           <property name="sizeHint" stdset="0">
            <size>
             <width>20</width>
             <height>40</height>
            </size>
           </property>
          </spacer>
         </item>
         <item>
          <widget class="QPushButton" name="info">
           <property name="minimumSize">
            <size>
             <width>211</width>
             <height>31</height>
            </size>
           </property>
           <property name="font">
            <font>
             <weight>75</weight>
             <bold>true</bold>
            </font>
           </property>
           <property name="styleSheet">
            <string notr="true">#info {
background-color: rgb(151, 102, 255);
/*background-color: rgb(0, 139, 247);*/
    color: rgb(255, 255, 255);
border-radius: 15px; /* Задайте радиус, чтобы сделать края овальными */
padding: 2px;}


#info:hover{
background-color: rgb(164, 205, 217);
}</string>
           </property>
           <property name="text">
            <string>Дополнительная информация</string>
           </property>
          </widget>
         </item>
        </layout>
       </item>
      </layout>
     </widget>
    </item>
   </layout>
  </widget>
 </widget>
 <resources/>
 <connections/>
</ui>

问题解释:

  • 在工作版本中,所有按钮始终保持相同的大小,但在缩放窗口时会移至中间(第二个屏幕截图)。
  • 但第二个版本不起作用 - 按钮总是增加窗口的宽度,在我提供的屏幕截图中清晰可见。(第四张截图,右侧窗口)

我们需要确保在(第四个屏幕截图)中,右侧窗口的按钮保持相同的大小,并在缩放窗口时移动到中心。

python
  • 1 1 个回答
  • 35 Views

1 个回答

  • Voted
  1. Best Answer
    S. Nick
    2024-07-22T07:21:12Z2024-07-22T07:21:12Z

    在工作版本中

    在此输入图像描述


    不工作版本

    在此输入图像描述

    • 1

相关问题

  • 是否可以以某种方式自定义 QTabWidget?

  • telebot.anihelper.ApiException 错误

  • Python。检查一个数字是否是 3 的幂。输出 无

  • 解析多个响应

  • 交换两个数组的元素,以便它们的新内容也反转

Sidebar

Stats

  • 问题 10021
  • Answers 30001
  • 最佳答案 8000
  • 用户 6900
  • 常问
  • 回答
  • Marko Smith

    我看不懂措辞

    • 1 个回答
  • Marko Smith

    请求的模块“del”不提供名为“default”的导出

    • 3 个回答
  • Marko Smith

    "!+tab" 在 HTML 的 vs 代码中不起作用

    • 5 个回答
  • Marko Smith

    我正在尝试解决“猜词”的问题。Python

    • 2 个回答
  • Marko Smith

    可以使用哪些命令将当前指针移动到指定的提交而不更改工作目录中的文件?

    • 1 个回答
  • Marko Smith

    Python解析野莓

    • 1 个回答
  • Marko Smith

    问题:“警告:检查最新版本的 pip 时出错。”

    • 2 个回答
  • Marko Smith

    帮助编写一个用值填充变量的循环。解决这个问题

    • 2 个回答
  • Marko Smith

    尽管依赖数组为空,但在渲染上调用了 2 次 useEffect

    • 2 个回答
  • Marko Smith

    数据不通过 Telegram.WebApp.sendData 发送

    • 1 个回答
  • Martin Hope
    Alexandr_TT 2020年新年大赛! 2020-12-20 18:20:21 +0000 UTC
  • Martin Hope
    Alexandr_TT 圣诞树动画 2020-12-23 00:38:08 +0000 UTC
  • Martin Hope
    Air 究竟是什么标识了网站访问者? 2020-11-03 15:49:20 +0000 UTC
  • Martin Hope
    Qwertiy 号码显示 9223372036854775807 2020-07-11 18:16:49 +0000 UTC
  • Martin Hope
    user216109 如何为黑客设下陷阱,或充分击退攻击? 2020-05-10 02:22:52 +0000 UTC
  • Martin Hope
    Qwertiy 并变成3个无穷大 2020-11-06 07:15:57 +0000 UTC
  • Martin Hope
    koks_rs 什么是样板代码? 2020-10-27 15:43:19 +0000 UTC
  • Martin Hope
    Sirop4ik 向 git 提交发布的正确方法是什么? 2020-10-05 00:02:00 +0000 UTC
  • Martin Hope
    faoxis 为什么在这么多示例中函数都称为 foo? 2020-08-15 04:42:49 +0000 UTC
  • Martin Hope
    Pavel Mayorov 如何从事件或回调函数中返回值?或者至少等他们完成。 2020-08-11 16:49:28 +0000 UTC

热门标签

javascript python java php c# c++ html android jquery mysql

Explore

  • 主页
  • 问题
    • 热门问题
    • 最新问题
  • 标签
  • 帮助

Footer

RError.com

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

帮助

© 2023 RError.com All Rights Reserve   沪ICP备12040472号-5