#10417 Use radiobuttons for single selection in lists

This commit is contained in:
Magne Sjaastad 2023-06-23 16:04:44 +02:00
parent aff2e7158f
commit 34d83efaed
6 changed files with 213 additions and 1 deletions

View File

@ -215,7 +215,8 @@
<file>themes/dark/arrow-down.svg</file>
<file>themes/dark/arrow-up.svg</file>
<file>themes/dark/gripper.svg</file>
<file>themes/light/gripper.svg</file>
<file>themes/shared/radio-button-active.svg</file>
<file>themes/shared/radio-circle-active.svg</file>
<file>themes/dark/checkbox-checked.svg</file>
<file>themes/dark/checkbox-checked-disabled.svg</file>
<file>themes/dark/checkbox-unchecked.svg</file>

View File

@ -27,6 +27,20 @@ $plotGridColor: #394046; // Plot grid color
$auxiliaryCurveColor: #000000; // Auxiliary curve color
$externalInputColor: #e82257; // External input background color
QTreeView[state="UseRadioButtons"] {
color: $textColor;
selection-color: $textColor;
}
QTreeView[state="UseRadioButtons"]::indicator:checked {
image: url(:/themes/shared/radio-button-active.svg);
}
QTreeView[state="UseRadioButtons"]::indicator:unchecked {
image: url(:/themes/shared/radio-circle-active.svg);
}
svg {
stroke: white;
stroke-width: 2;

View File

@ -24,6 +24,21 @@ $plotGridColor: #394046; // Plot grid color
$auxiliaryCurveColor: #000000; // Auxiliary curve color
$externalInputColor: #fff2a7; // Background color for external input fields
QTreeView[state="UseRadioButtons"] {
color: $textColor;
selection-color: $textColor;
}
QTreeView[state="UseRadioButtons"]::indicator:checked {
image: url(:/themes/shared/radio-button-active.svg);
}
QTreeView[state="UseRadioButtons"]::indicator:unchecked {
image: url(:/themes/shared/radio-circle-active.svg);
}
/*
*/

View File

@ -0,0 +1,88 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 24.3.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
version="1.1"
id="Layer_1"
x="0px"
y="0px"
viewBox="0 0 24 24"
style="enable-background:new 0 0 24 24;"
xml:space="preserve"
sodipodi:docname="radio-button-active.svg"
inkscape:version="1.2.2 (732a01da63, 2022-12-09)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"><defs
id="defs36"><rect
x="3.3651412"
y="2.1265823"
width="18.835443"
height="19.793574"
id="rect250" /></defs><sodipodi:namedview
id="namedview34"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="false"
inkscape:zoom="42.791667"
inkscape:cx="10.738072"
inkscape:cy="10.703018"
inkscape:window-width="2560"
inkscape:window-height="1369"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="Layer_1" />
<style
type="text/css"
id="style20">
.st0{fill:url(#SVGID_1_);stroke:#8F9090;stroke-width:0.75;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;}
.st1{fill:none;stroke:#8DC584;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;}
</style>
<linearGradient
id="SVGID_1_"
gradientUnits="userSpaceOnUse"
x1="1.1804"
y1="12.4846"
x2="22.8196"
y2="12.4846">
<stop
offset="1.118836e-07"
style="stop-color:#9D9D9C"
id="stop22" />
<stop
offset="0.5652"
style="stop-color:#CECECE"
id="stop24" />
<stop
offset="1"
style="stop-color:#5C5C5B"
id="stop26" />
</linearGradient>
<ellipse
style="fill:none;stroke:#999999;stroke-width:2.06358;stroke-miterlimit:3.4;stroke-dasharray:none"
id="path848"
ry="9.2489386"
rx="9.2021999"
cy="12"
cx="12" /><path
style="fill:#999999;fill-opacity:1;stroke:#999999;stroke-width:5.87689;stroke-miterlimit:3.4;stroke-dasharray:none;stroke-opacity:1"
id="path964"
sodipodi:type="arc"
sodipodi:cx="11.871469"
sodipodi:cy="12.000001"
sodipodi:rx="3.6184046"
sodipodi:ry="3.7936726"
sodipodi:start="0"
sodipodi:end="6.2730014"
sodipodi:open="true"
sodipodi:arc-type="arc"
d="m 15.489873,12.000001 a 3.6184046,3.7936726 0 0 1 -3.609192,3.79366 3.6184046,3.7936726 0 0 1 -3.6275702,-3.774343 3.6184046,3.7936726 0 0 1 3.5907212,-3.812879 3.6184046,3.7936726 0 0 1 3.645854,3.754928" /></svg>

After

Width:  |  Height:  |  Size: 2.7 KiB

View File

@ -0,0 +1,76 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Generator: Adobe Illustrator 24.3.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg
version="1.1"
id="Layer_1"
x="0px"
y="0px"
viewBox="0 0 24 24"
style="enable-background:new 0 0 24 24;"
xml:space="preserve"
sodipodi:docname="radio-circle-active.svg"
inkscape:version="1.2.2 (732a01da63, 2022-12-09)"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns="http://www.w3.org/2000/svg"
xmlns:svg="http://www.w3.org/2000/svg"><defs
id="defs36"><rect
x="3.3651412"
y="2.1265823"
width="18.835443"
height="19.793574"
id="rect250" /></defs><sodipodi:namedview
id="namedview34"
pagecolor="#ffffff"
bordercolor="#000000"
borderopacity="0.25"
inkscape:showpageshadow="2"
inkscape:pageopacity="0.0"
inkscape:pagecheckerboard="0"
inkscape:deskcolor="#d1d1d1"
showgrid="false"
inkscape:zoom="42.791667"
inkscape:cx="10.644596"
inkscape:cy="10.42259"
inkscape:window-width="2560"
inkscape:window-height="1369"
inkscape:window-x="-8"
inkscape:window-y="-8"
inkscape:window-maximized="1"
inkscape:current-layer="Layer_1" />
<style
type="text/css"
id="style20">
.st0{fill:url(#SVGID_1_);stroke:#8F9090;stroke-width:0.75;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;}
.st1{fill:none;stroke:#8DC584;stroke-width:2;stroke-linecap:round;stroke-linejoin:round;stroke-miterlimit:10;}
</style>
<linearGradient
id="SVGID_1_"
gradientUnits="userSpaceOnUse"
x1="1.1804"
y1="12.4846"
x2="22.8196"
y2="12.4846">
<stop
offset="1.118836e-07"
style="stop-color:#9D9D9C"
id="stop22" />
<stop
offset="0.5652"
style="stop-color:#CECECE"
id="stop24" />
<stop
offset="1"
style="stop-color:#5C5C5B"
id="stop26" />
</linearGradient>
<ellipse
style="fill:none;stroke:#999999;stroke-width:2.06358;stroke-miterlimit:3.4;stroke-dasharray:none"
id="path848"
ry="9.2489386"
rx="9.2021999"
cy="12"
cx="12" /></svg>

After

Width:  |  Height:  |  Size: 2.1 KiB

View File

@ -303,6 +303,24 @@ void PdmUiTreeSelectionEditor::configureAndUpdateUi( const QString& uiConfigName
m_textFilterLineEdit->setPlaceholderText( "Type to filter items" );
}
// Set the CSS property to use radio buttons instead of check boxes
// This is done by setting the "state" property to "UseRadioButtons"
QString stateText;
if ( m_useSingleSelectionMode )
{
stateText = "UseRadioButtons";
}
std::string propertyName = "state";
auto propertyValue = m_treeView->property( propertyName.data() ).toString();
if ( propertyValue != stateText )
{
m_treeView->setProperty( propertyName.data(), stateText );
m_treeView->style()->unpolish( m_treeView );
m_treeView->style()->polish( m_treeView );
m_treeView->update();
}
// It is required to use a timer here, as the layout of the widgets are handled by events
// Calling scrollTo() here has no effect, or scrolls to wrong location
QTimer::singleShot( 150, this, SLOT( slotScrollToFirstCheckedItem() ) );