1

我想实现类似于这张图片的东西:

在此处输入图像描述

除了顶层(“地址栏”、“表单”和“用户名...”)应该是单选按钮。

这个想法是子级别应该根据单选按钮的状态启用或禁用。并且子级别应该向右移动,如图所示。

可以以优雅的方式完成 Qt 吗?

4

2 回答 2

0

我想说一个简单QVBoxLayout的顶层,每个“子级别”都有一个QHBoxLayout具有固定大小的间隔项作为第一个子项,并且一个QVBoxLayout包含子选项。

然后可以通过禁用“子级别”小部件来禁用所有子选项。

于 2016-12-06T11:32:22.367 回答
0

只需将这些子项目(如“浏览历史”、“收藏夹”……)放入一个单独的位置,QWidget然后将该小部件的QWidget::setEnabled()插槽与“地址栏”单选按钮的QAbstractButton::toggled()信号连接起来。

这是一个 Qt Designer 的.ui文件(带有工作的信号槽连接,在 Designer 中尝试Ctrl+ R),它演示了这个想法:

<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
 <class>Form</class>
 <widget class="QWidget" name="Form">
  <property name="geometry">
   <rect>
    <x>0</x>
    <y>0</y>
    <width>170</width>
    <height>178</height>
   </rect>
  </property>
  <property name="windowTitle">
   <string>Form</string>
  </property>
  <layout class="QVBoxLayout" name="verticalLayout">
   <item>
    <widget class="QRadioButton" name="radioButton">
     <property name="text">
      <string>RadioButton</string>
     </property>
     <property name="checked">
      <bool>true</bool>
     </property>
    </widget>
   </item>
   <item>
    <widget class="QWidget" name="widget" native="true">
     <layout class="QVBoxLayout" name="verticalLayout_2">
      <item>
       <widget class="QCheckBox" name="checkBox">
        <property name="text">
         <string>CheckBox</string>
        </property>
       </widget>
      </item>
      <item>
       <widget class="QCheckBox" name="checkBox_2">
        <property name="text">
         <string>CheckBox</string>
        </property>
       </widget>
      </item>
      <item>
       <widget class="QCheckBox" name="checkBox_3">
        <property name="text">
         <string>CheckBox</string>
        </property>
       </widget>
      </item>
     </layout>
    </widget>
   </item>
   <item>
    <widget class="QRadioButton" name="radioButton_2">
     <property name="text">
      <string>RadioButton</string>
     </property>
    </widget>
   </item>
   <item>
    <widget class="QRadioButton" name="radioButton_3">
     <property name="text">
      <string>RadioButton</string>
     </property>
    </widget>
   </item>
  </layout>
 </widget>
 <resources/>
 <connections>
  <connection>
   <sender>radioButton</sender>
   <signal>toggled(bool)</signal>
   <receiver>widget</receiver>
   <slot>setEnabled(bool)</slot>
   <hints>
    <hint type="sourcelabel">
     <x>84</x>
     <y>17</y>
    </hint>
    <hint type="destinationlabel">
     <x>84</x>
     <y>77</y>
    </hint>
   </hints>
  </connection>
 </connections>
</ui>
于 2016-12-07T07:27:19.477 回答