Hide useless action buttons when list widget is read only

This commit is contained in:
Nyall Dawson 2024-03-25 12:03:36 +10:00
parent 63c1d5cfc0
commit 317aae6f0e
2 changed files with 76 additions and 46 deletions

View File

@ -71,4 +71,15 @@ void QgsTableWidgetBase::setReadOnly( bool readOnly )
addButton->setEnabled( !mReadOnly ); addButton->setEnabled( !mReadOnly );
removeButton->setEnabled( !mReadOnly && tableView->selectionModel()->hasSelection() ); removeButton->setEnabled( !mReadOnly && tableView->selectionModel()->hasSelection() );
if ( mReadOnly )
{
mWidgetActions->hide();
layout()->setSpacing( 0 );
}
else
{
mWidgetActions->show();
layout()->setSpacing( 6 );
}
} }

View File

@ -58,55 +58,74 @@
</widget> </widget>
</item> </item>
<item> <item>
<layout class="QVBoxLayout" name="mActionLayout"> <widget class="QWidget" name="mWidgetActions" native="true">
<item> <layout class="QVBoxLayout" name="verticalLayout">
<widget class="QToolButton" name="addButton"> <property name="leftMargin">
<property name="toolTip"> <number>0</number>
<string>Add entry</string> </property>
</property> <property name="topMargin">
<property name="text"> <number>0</number>
<string>…</string> </property>
</property> <property name="rightMargin">
<property name="icon"> <number>0</number>
<iconset resource="../../images/images.qrc"> </property>
<normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset> <property name="bottomMargin">
</property> <number>0</number>
</widget> </property>
</item> <item>
<item> <widget class="QToolButton" name="addButton">
<widget class="QToolButton" name="removeButton"> <property name="toolTip">
<property name="enabled"> <string>Add entry</string>
<bool>false</bool> </property>
</property> <property name="text">
<property name="toolTip"> <string>…</string>
<string>Remove entry</string> </property>
</property> <property name="icon">
<property name="text"> <iconset resource="../../images/images.qrc">
<string>…</string> <normaloff>:/images/themes/default/symbologyAdd.svg</normaloff>:/images/themes/default/symbologyAdd.svg</iconset>
</property> </property>
<property name="icon"> </widget>
<iconset resource="../../images/images.qrc"> </item>
<normaloff>:/images/themes/default/symbologyRemove.svg</normaloff>:/images/themes/default/symbologyRemove.svg</iconset> <item>
</property> <widget class="QToolButton" name="removeButton">
</widget> <property name="enabled">
</item> <bool>false</bool>
<item> </property>
<spacer name="verticalSpacer"> <property name="toolTip">
<property name="orientation"> <string>Remove entry</string>
<enum>Qt::Vertical</enum> </property>
</property> <property name="text">
<property name="sizeHint" stdset="0"> <string>…</string>
<size> </property>
<width>20</width> <property name="icon">
<height>40</height> <iconset resource="../../images/images.qrc">
</size> <normaloff>:/images/themes/default/symbologyRemove.svg</normaloff>:/images/themes/default/symbologyRemove.svg</iconset>
</property> </property>
</spacer> </widget>
</item> </item>
</layout> <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>
</layout>
</widget>
</item> </item>
</layout> </layout>
</widget> </widget>
<tabstops>
<tabstop>tableView</tabstop>
<tabstop>addButton</tabstop>
<tabstop>removeButton</tabstop>
</tabstops>
<resources> <resources>
<include location="../../images/images.qrc"/> <include location="../../images/images.qrc"/>
</resources> </resources>