-2

I'm encountering an issue where the window and its components in a Qt Designer-designed interface become very small and almost invisible after compiling and running the code. The text on the components also becomes extremely small, making it difficult to read. I'm using Qt version 5.15. I have designed the interface in Qt Designer with various components and layouts. However, when I compile and run the code, the window's size and the size of the components become very small, and it's hard to see the text on the components.

I have attempted the following solutions without success:

Trying to adjust the size properties of the window and components, but it has no effect. Checking the display settings of the operating system to ensure the scaling factor is set correctly. Ensuring there are no direct modifications to the component sizes in the code. I am seeking help to find a solution to this problem. Any assistance would be greatly appreciated!

(Please adjust the code and details as necessary and provide sufficient context in your question for other developers to better understand and answer your issue.)enter image description here

enter image description here

window1.ui

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Window1</class>
 <widget class="QMainWindow" name="Window1">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>411</width>
    <height>300</height>
   </rect>
  </property>
  <property name="minimumSize">
   <size>
    <width>300</width>
    <height>300</height>
   </size>
  </property>
  <property name="windowTitle">
   <string>Window1</string>
  </property>
  <property name="dockNestingEnabled">
   <bool>true</bool>
  </property>
  <widget class="QWidget" name="centralwidget">
   <widget class="QLabel" name="label">
    <property name="geometry">
     <rect>
      <x>110</x>
      <y>0</y>
      <width>141</width>
      <height>41</height>
     </rect>
    </property>
    <property name="text">
     <string>&lt;html&gt;&lt;head/&gt;&lt;body&gt;&lt;p&gt;&lt;span style=&quot; font-size:16pt; font-weight:700;&quot;&gt;本地信息获取&lt;/span&gt;&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;</string>
    </property>
   </widget>
   <widget class="QWidget" name="horizontalLayoutWidget">
    <property name="geometry">
     <rect>
      <x>40</x>
      <y>30</y>
      <width>291</width>
      <height>31</height>
     </rect>
    </property>
    <layout class="QHBoxLayout" name="horizontalLayout">
     <item>
      <widget class="QLabel" name="label_2">
       <property name="text">
        <string>本地主机名</string>
       </property>
      </widget>
     </item>
     <item>
      <widget class="QLineEdit" name="localhostname"/>
     </item>
     <item>
      <widget class="QPushButton" name="flushlocal">
       <property name="text">
        <string>更新</string>
       </property>
      </widget>
     </item>
    </layout>
   </widget>
   <widget class="QWidget" name="horizontalLayoutWidget_2">
    <property name="geometry">
     <rect>
      <x>80</x>
      <y>230</y>
      <width>221</width>
      <height>22</height>
     </rect>
    </property>
    <layout class="QHBoxLayout" name="horizontalLayout_2">
     <item>
      <widget class="QPushButton" name="hostdecoder">
       <property name="text">
        <string>域名解析器</string>
       </property>
      </widget>
     </item>
     <item>
      <widget class="QPushButton" name="messaging_simulator">
       <property name="text">
        <string>通信模拟器</string>
       </property>
      </widget>
     </item>
    </layout>
   </widget>
   <widget class="QGroupBox" name="groupBox">
    <property name="geometry">
     <rect>
      <x>40</x>
      <y>60</y>
      <width>321</width>
      <height>161</height>
     </rect>
    </property>
    <property name="title">
     <string>GroupBox</string>
    </property>
    <widget class="QTextBrowser" name="localips">
     <property name="geometry">
      <rect>
       <x>90</x>
       <y>20</y>
       <width>221</width>
       <height>131</height>
      </rect>
     </property>
    </widget>
    <widget class="QLabel" name="label_1">
     <property name="geometry">
      <rect>
       <x>20</x>
       <y>20</y>
       <width>51</width>
       <height>20</height>
      </rect>
     </property>
     <property name="text">
      <string>本机IP</string>
     </property>
    </widget>
    <widget class="QCheckBox" name="chkOnlyIPv4">
     <property name="geometry">
      <rect>
       <x>10</x>
       <y>50</y>
       <width>81</width>
       <height>22</height>
      </rect>
     </property>
     <property name="text">
      <string>IPv4 only</string>
     </property>
    </widget>
   </widget>
  </widget>
  <widget class="QMenuBar" name="menubar">
   <property name="geometry">
    <rect>
     <x>0</x>
     <y>0</y>
     <width>411</width>
     <height>21</height>
    </rect>
   </property>
  </widget>
  <widget class="QStatusBar" name="statusbar"/>
 </widget>
 <resources/>
 <connections/>
</ui>

LEO
  • 1
  • 3
  • I am not sure there is enough information to find or fix the cause of the problem however as a workaround I believe you can add a minimum size or just width to your widget. – drescherjm Jul 10 '23 at 15:03
  • You forgot to add a [layout](https://doc.qt.io/qt-6/layout.html) to your widget. – chehrlic Jul 10 '23 at 15:11
  • You don't appear to be using layouts in your Qt project, see https://doc.qt.io/qt-6/designer-layouts.html for further details. – chris_se Jul 10 '23 at 15:11
  • so disappointing, i tried to set the minimum size and used layout, but any of this did't change the strange disappearance. – LEO Jul 10 '23 at 17:00
  • Does the problem occur if you preview your form? (preview can be done from `Qt Designer->Tools->Form Editor->Preview`) If it does, please share your `.ui` file. If not, please show us how we can reproduce the problem. – Abderrahmene Rayene Mihoub Jul 10 '23 at 17:40
  • the preview is fine actuallymihoub-abderrahmene-rayene – LEO Jul 10 '23 at 17:48
  • 1
    You're not using a layout for your centralWidget which contains your other widgets, please read the links already linked here in the comments above and these: [Auto-expanding layout with Qt-Designer](https://stackoverflow.com/questions/3492739/auto-expanding-layout-with-qt-designer), [Qt Layout on QMainWindow](https://stackoverflow.com/questions/1508939/qt-layout-on-qmainwindow). – Abderrahmene Rayene Mihoub Jul 10 '23 at 17:56
  • it won't work for this monster, i have tried, it just keep the same, but it can work at 6.4.3, it's appearance is the same as i designed but in 5.14 ,it just a mess – LEO Jul 11 '23 at 01:21

1 Answers1

0

I added

if(QT_VERSION >= QT_VERSION_CHECK(5, 6, 0))
        QCoreApplication::setAttribute(Qt::AA_EnableHighDpiScaling);

beforeQApplication a(argc, argv); and the ui back to fine.

LEO
  • 1
  • 3