嵌套結構我想實現類似於此圖的內容:與QRadioButtons
除了頂層(「您的地址欄」,「形式」和「用戶名......」)應該是單選按鈕。
這個想法是,應根據單選按鈕的狀態啓用或禁用子級。應該像圖片上的那樣向右移動子平面。
這可以通過優雅的方式完成Qt嗎?
嵌套結構我想實現類似於此圖的內容:與QRadioButtons
除了頂層(「您的地址欄」,「形式」和「用戶名......」)應該是單選按鈕。
這個想法是,應根據單選按鈕的狀態啓用或禁用子級。應該像圖片上的那樣向右移動子平面。
這可以通過優雅的方式完成Qt嗎?
我會說一個簡單的QVBoxLayout
頂級和每個「子級」有一個QHBoxLayout
與固定大小的間隔項目作爲第一個孩子和QVBoxLayout
包含子選項。
禁用所有子選項可以簡單地通過禁用「sublevel」小部件來完成。
只需將這些子項目(如「瀏覽歷史記錄」,「收藏夾」...)分隔成QWidget
,並使用「地址欄」單選按鈕的QAbstractButton::toggled()
信號將該小部件的QWidget::setEnabled()
插槽連接起來。
這是一個Qt設計師的的.ui文件(工作信號槽連接,請嘗試按Ctrl +[R在Designer)演示的想法:
<?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>