4

我最近搬到 Mac OS X 并注意到我的一个应用程序中的对话框看起来有点奇怪......我有几个对话框,它们基本上是一个简单的表单,具有可配置的路径:

标签:<QLineEdit> <QPushButton (opens file dialog)>
标签: ...

对话框以 QGridLayout 组织,在 Ubuntu 上看起来不错:
Ubuntu 上的对话框

在 Mac OS X 上,QPushButtons 行下方有一个很大的空白区域,这让整个事情看起来很奇怪:
OS X 上的对话框

我发现这个错误报告显然是默默关闭的: https ://bugreports.qt.io/browse/QTBUG-2699

用户界面代码:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Dialog</class>
 <widget class="QDialog" name="Dialog">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>431</width>
    <height>235</height>
   </rect>
  </property>
  <property name="sizePolicy">
   <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
    <horstretch>0</horstretch>
    <verstretch>0</verstretch>
   </sizepolicy>
  </property>
  <property name="windowTitle">
   <string>PDF Export</string>
  </property>
  <property name="windowIcon">
   <iconset resource="resources.qrc">
    <normaloff>:/images/images/application-pdf.png</normaloff>:/images/images/application-pdf.png</iconset>
  </property>
  <layout class="QVBoxLayout" name="verticalLayout">
   <item>
    <layout class="QGridLayout" name="gridLayout">
     <item row="0" column="1">
      <widget class="QLineEdit" name="texPath">
       <property name="readOnly">
        <bool>true</bool>
       </property>
      </widget>
     </item>
     <item row="1" column="0">
      <widget class="QLabel" name="label">
       <property name="text">
        <string>Auszubildender:</string>
       </property>
       <property name="buddy">
        <cstring>traineeName</cstring>
       </property>
      </widget>
     </item>
     <item row="1" column="1" colspan="2">
      <widget class="QLineEdit" name="traineeName"/>
     </item>
     <item row="2" column="0">
      <widget class="QLabel" name="label_2">
       <property name="text">
        <string>Ausbilder:</string>
       </property>
       <property name="buddy">
        <cstring>instructorName</cstring>
       </property>
      </widget>
     </item>
     <item row="2" column="1" colspan="2">
      <widget class="QLineEdit" name="instructorName"/>
     </item>
     <item row="3" column="0">
      <widget class="QLabel" name="label_5">
       <property name="text">
        <string>Name der Firma:</string>
       </property>
       <property name="buddy">
        <cstring>companyName</cstring>
       </property>
      </widget>
     </item>
     <item row="3" column="1" colspan="2">
      <widget class="QLineEdit" name="companyName"/>
     </item>
     <item row="4" column="0">
      <widget class="QLabel" name="label_3">
       <property name="text">
        <string>Datum der Unterschriften:</string>
       </property>
       <property name="buddy">
        <cstring>dateEdit</cstring>
       </property>
      </widget>
     </item>
     <item row="4" column="1" colspan="2">
      <widget class="QDateEdit" name="dateEdit">
       <property name="displayFormat">
        <string>dd.MM.yyyy</string>
       </property>
       <property name="calendarPopup">
        <bool>true</bool>
       </property>
      </widget>
     </item>
     <item row="0" column="2">
      <widget class="QPushButton" name="browseButton">
       <property name="text">
        <string/>
       </property>
       <property name="icon">
        <iconset resource="resources.qrc">
         <normaloff>:/images/images/document-open.png</normaloff>:/images/images/document-open.png</iconset>
       </property>
      </widget>
     </item>
     <item row="0" column="0">
      <widget class="QLabel" name="label_4">
       <property name="text">
        <string>Pfad zum TEX-Template:</string>
       </property>
       <property name="buddy">
        <cstring>texPath</cstring>
       </property>
      </widget>
     </item>
    </layout>
   </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="QPushButton" name="cancelButton">
       <property name="text">
        <string>Abbrechen</string>
       </property>
      </widget>
     </item>
     <item>
      <widget class="QPushButton" name="generateButton">
       <property name="text">
        <string>PDF generieren...</string>
       </property>
       <property name="icon">
        <iconset resource="resources.qrc">
         <normaloff>:/images/images/arrow-right.png</normaloff>:/images/images/arrow-right.png</iconset>
       </property>
      </widget>
     </item>
    </layout>
   </item>
  </layout>
 </widget>
 <tabstops>
  <tabstop>texPath</tabstop>
  <tabstop>browseButton</tabstop>
  <tabstop>traineeName</tabstop>
  <tabstop>instructorName</tabstop>
  <tabstop>companyName</tabstop>
  <tabstop>dateEdit</tabstop>
  <tabstop>cancelButton</tabstop>
  <tabstop>generateButton</tabstop>
 </tabstops>
 <resources>
  <include location="resources.qrc"/>
 </resources>
 <connections>
  <connection>
   <sender>cancelButton</sender>
   <signal>clicked()</signal>
   <receiver>Dialog</receiver>
   <slot>reject()</slot>
   <hints>
    <hint type="sourcelabel">
     <x>246</x>
     <y>221</y>
    </hint>
    <hint type="destinationlabel">
     <x>133</x>
     <y>152</y>
    </hint>
   </hints>
  </connection>
 </connections>
</ui>

有没有什么办法解决这一问题?

4

2 回答 2

2

您应该使用 aQButtonBox作为您的按钮,而不是自定义布局中的离散按钮。您需要手动添加 PDF 生成按钮。

作为一种临时解决方法,您需要减少 OS X 上的底部边距大小。希望它最终会得到修复。

Dialog::Dialog(QWidget *parent) :
    QDialog(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    QPushButton * btn = new QPushButton(tr("PDF Generieren..."));
    btn->setIcon(QIcon(":/images/images/arrow-right.png"));
    ui->buttonBox->addButton(btn, QDialogButtonBox::AcceptRole);
#if (QT_VERSION <= QT_VERSION_CHECK(5, 1, 1)) && defined(QT_OS_MAC)
    QMargins margins = layout()->contentsMargins();
    margins.setBottom(margins.bottom() - 6);
    layout()->setContentsMargins(margins);
#endif
}
于 2013-09-05T01:26:32.803 回答
-1

由于这在 Qt 5.6 中仍然是一个问题,因此这里有一个可能的解决方案:创建自己的QProxyStyle并重新subElementRect实现SE_PushButtonLayoutItem. 例如,返回默认值QCommonStyle::subElementRect()

于 2016-06-15T14:13:21.847 回答