[Interest] Uncheck Button in QML ButtonGroup
Jérôme Godbout
jerome at bodycad.com
Wed Aug 16 16:12:18 CEST 2017
Small fix to double check on single entry, my bad:
ExclusiveGroup
{
id: group_
property var lastClicked: null
function unselectAll()
{
[b1_, b2_].forEach(function(v){ return v.checked = false; });
current = null;
lastClicked = null;
}
}
Column
{
CheckBox
{
id: b1_
text: 'b1'
exclusiveGroup: group_
onClicked:
{
if(checked && group_.lastClicked == b1_)
group_.unselectAll();
else
group_.lastClicked = b1_;
}
}
CheckBox
{
id: b2_
text: 'b2'
exclusiveGroup: group_
onClicked:
{
if(checked && group_.lastClicked == b2_)
group_.unselectAll();
else
group_.lastClicked = b2_;
}
}
}
[image: bodycad] <https://www.bodycad.com/>
Jerome Godbout
Software Developer
2035 rue du Haut-Bord, Québec, QC, Canada. G1N 4R7
T: +1 418 527-1388
E: jerome at bodycad.com
www.bodycad.com
The contents of this email message and any attachments are intended solely
for the addressee(s) and may contain confidential and/or privileged
information and may be legally protected from disclosure. If you are not
the intended recipient of this message or their agent, or if this message
has been addressed to you in error, please immediately alert the sender by
reply email and then delete this message and any attachments. If you are
not the intended recipient, you are hereby notified that any use,
dissemination, copying, or storage of this message or its attachments is
strictly prohibited.
Le contenu de ce message et les pièces jointes sont destinés uniquement
pour le(s) destinataire(s) et peuvent contenir des informations
confidentielles et / ou privilégiées qui peuvent être protégées légalement
contre toute divulgation. Si vous n'êtes pas le destinataire de ce message
ou son agent, ou si ce message vous a été adressé par erreur, s’il vous
plaît avertir immédiatement l'expéditeur par courriel de réponse, puis
supprimer ce message et les pièces jointes. Si vous n'êtes pas le
destinataire prévu, vous êtes par la présente informé que toute
utilisation, diffusion, copie, ou stockage de ce message ou de ses pièces
jointes est strictement interdit.
On Wed, Aug 16, 2017 at 10:10 AM, Jérôme Godbout <jerome at bodycad.com> wrote:
> It's sad that the clicked event is sent after the exclusive group is
> handled (since we cannot affect or cancel it, so here's a work around):
>
> ExclusiveGroup
> {
> id: group_
> property var lastClicked: null
> function unselectAll()
> {
> [b1_, b2_].forEach(function(v){ return v.checked = false; });
> current = null;
> }
> }
>
> Column
> {
> CheckBox
> {
> id: b1_
> text: 'b1'
> exclusiveGroup: group_
> onClicked:
> {
> if(checked && group_.lastClicked == b1_)
> group_.unselectAll();
> group_.lastClicked = b1_;
> }
> }
>
> CheckBox
> {
> id: b2_
> text: 'b2'
> exclusiveGroup: group_
> onClicked:
> {
> if(checked && group_.lastClicked == b2_)
> group_.unselectAll();
> group_.lastClicked = b2_;
> }
> }
> }
>
> This should allow you to single select a checkbox and if reclick on 1 to
> deselect them.
>
>
> [image: bodycad] <https://www.bodycad.com/>
> Jerome Godbout
> Software Developer
> 2035 rue du Haut-Bord, Québec, QC, Canada. G1N 4R7
> T: +1 418 527-1388 <(418)%20527-1388>
> E: jerome at bodycad.com
> www.bodycad.com
>
> The contents of this email message and any attachments are intended solely
> for the addressee(s) and may contain confidential and/or privileged
> information and may be legally protected from disclosure. If you are not
> the intended recipient of this message or their agent, or if this message
> has been addressed to you in error, please immediately alert the sender by
> reply email and then delete this message and any attachments. If you are
> not the intended recipient, you are hereby notified that any use,
> dissemination, copying, or storage of this message or its attachments is
> strictly prohibited.
>
> Le contenu de ce message et les pièces jointes sont destinés uniquement
> pour le(s) destinataire(s) et peuvent contenir des informations
> confidentielles et / ou privilégiées qui peuvent être protégées légalement
> contre toute divulgation. Si vous n'êtes pas le destinataire de ce message
> ou son agent, ou si ce message vous a été adressé par erreur, s’il vous
> plaît avertir immédiatement l'expéditeur par courriel de réponse, puis
> supprimer ce message et les pièces jointes. Si vous n'êtes pas le
> destinataire prévu, vous êtes par la présente informé que toute
> utilisation, diffusion, copie, ou stockage de ce message ou de ses pièces
> jointes est strictement interdit.
>
> On Wed, Aug 16, 2017 at 8:48 AM, Bullinger, Julius <
> julius.bullinger at intel.com> wrote:
>
>> *From:* Jérôme Godbout [mailto:jerome at bodycad.com]
>> *Sent:* Wednesday, August 16, 2017 14:32
>> *To:* Bullinger, Julius <julius.bullinger at intel.com>
>> *Cc:* interest at qt-project.org
>> *Subject:* Re: [Interest] Uncheck Button in QML ButtonGroup
>>
>>
>>
>> > Here's what I did:
>>
>> >
>>
>> > function unselectAllButton()
>>
>> > {
>>
>> > [idButton1, idButton2, ...].forEach(function(v){ v.checked = false;
>> });
>>
>> > group.checkedButton = null;
>>
>> > }
>>
>> >
>>
>> > I didn't test it with ButtonGroup, but only with QtQuick Controls 1
>> and ExclusiveGroup
>>
>> > work this way (change the group.checkButton for group.current), so I
>> guess it should
>>
>> > work too.
>>
>>
>>
>> And you can toggle the checked state when clicking on a button with that?
>> On which trigger is this function called?
>>
>>
>>
>> Thanks,
>>
>> Julius
>>
>>
>>
>>
>>
>> Intel Deutschland GmbH
>> Registered Address: Am Campeon 10-12, 85579 Neubiberg, Germany
>> Tel: +49 89 99 8853-0, www.intel.de
>> Managing Directors: Christin Eisenschmid, Christian Lamprechter
>> Chairperson of the Supervisory Board: Nicole Lau
>> Registered Office: Munich
>> Commercial Register: Amtsgericht Muenchen HRB 186928
>>
>> _______________________________________________
>> Interest mailing list
>> Interest at qt-project.org
>> http://lists.qt-project.org/mailman/listinfo/interest
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20170816/e300dafe/attachment.html>
More information about the Interest
mailing list