Radiobuttons and groups

Post

Posted
Rating:
#1 (In Topic #1797)
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’

more than one group of radiobuttons

Hi there ðŸ˜‡

As I had a fight with 2 groups of Radiobuttons on one form for some time today finally I read the manual,
(RTFM 😂) and see, the answer was just there:

The RadioButton class inherits its attributes from the Control class and is
used to implement a radio button control. RadioButton controls that share the
same parent
(in this case, the Panel container) are mutually exclusive. Only one
RadioButton can be selected at once.


What I did:
Without any container I put 3 Radiobuttons together and gave them the same group.
Then a put the next 2 Radiobuttons together beside the other and gave them to another
group. Then I wondered why it doesn't work selecting. One group affected the other
group when selecting.

The really simple solution was to give both of them different parents, e.g. Panels.

After that it worked as expected. 
Also the event for the same Buttongroup required a little workout,
I wanted the active Radiobutton become selected if the space bar is pressed

I named the Group "user", so the event…


Code

' for all Radiobuttons in the "user" Group
' the space key activates the Radiobutton with focus
Public Sub user_KeyPress()
  If Key.Code = Key.Space Then 
    Last.Value = True 'if space pressed select current optionbutton as active
  Endif
End


That's all, just for sharing. If it helps someone, the mission is accomplished.

Regards,
Yogi
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by Yogi)
#2
Guru
BruceSteers is in the usergroup ‘Guru’
Be aware that GTK and QT behave differently.

With QT you just press arrow keys and it runs through the RadioButtons selecting the next/previous one.

GTK does not.

I use code like this to make GTK emulate how QT behaves so it's the same on either…

Code


Public Sub RB_KeyPress()
  Dim NewControl As RadioButton

  If Env["GB_GUI"] Like "gb.gtk*" Then  ' do not do anything if QT
    Select Key.code
      Case Key.Up, Key.Left
        NewControl = Last.Previous
      Case Key.Down, Key.Right
        NewControl = Last.Next
    End Select
    If NewControl Then
      NewControl.Value = True
      NewControl.SetFocus
    Endif
  Endif

End
Online now: No Back to the top

Post

Posted
Rating:
#3
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’

BruceSteers said

Be aware that GTK and QT behave differently.

With QT you just press arrow keys and it runs through the RadioButtons selecting the next/previous one.

GTK does not.

I use code like this with GTK as it emulates how QT behaves…

[gb] Public Sub RadioB_KeyPress()   Dim NewControl As RadioButton   If Env["GB_GUI"] Like "gb.gtk*" Then  ' only do this if using GTK not QT     Select Key.code       Case Key.Up, Key.Left         NewControl = Last.Previous       Case Key.Down, Key.Right         NewControl = Last.Next     End Select     If NewControl Then       NewControl.Value = True       NewControl.SetFocus     Endif   Endif End [/gb]
 

Dear Bruce,
as I see this Forum is blessed by people like you (and of course others), jumping in at every possible situation.
Hopefully it is not too much wasted time, because I'm living from one moment to the other, forgetting things
done after not touched it for some while. Sure not only a problem of generation 60+ like me.

So I'm not a profession and I get sometimes confused after long year Windows presence, living with ease there.
First Ubuntu since 2 month with wayland.
Then recognising wayland is like snap and Google - trying to limit everything for securitys sake.
So changed to X11, seeing that some things do not behave like before - find the next solutions.

At the moment there is no idea how to change from GTK3 to something else and what is the "best" solution -
ok I'll ask "turkey" aka startpage.com.

More than 40 years back that would have been a challenge, and sure I had done it.

So I have fun just making some handy things to make living on the Laptop easier, shortening things.

So I think every distribution has its fans, maybe I find something else than Ubuntu…

For now I'm here and see the power of Gambas, using 0,01% (or less) of its features - like I did with Word etc.
just scraping the surface.

So you see I'm not experienced in Linux and how deep it will go we find out.

Thanks again for your efforts,
Regards,
Yogi
Online now: No Back to the top

Post

Posted
Rating:
Item has a rating of 5 (Liked by Yogi)
#4
Avatar
Administrator
gbWilly is in the usergroup ‘unknown’

Yogi said

At the moment there is no idea how to change from GTK3 to something else and what is the "best" solution -

Menu Project -> Properties -> Tab components -> deselect gb.gui and select gb.qt5 (or qt6) and click ok

A lot of what you are figuring out and explaining in your first post are basics explained in Gambas Book 1 in detail.
But figuring things out yourself, is my preferred manner of learning as it sticks better :lol:
 

gbWilly
- Gambas Dutch translator
- Gambas wiki content contributor
- Gambas debian/ubuntu package recipe contributor
- GambOS, a distro for learning Gambas and more…
- Gambas3 Debian/Ubuntu repositories


… there is always a Catch if things go wrong!
Online now: No Back to the top

Post

Posted
Rating:
#5
Guru
BruceSteers is in the usergroup ‘Guru’
Yep.

If your program uses gb.gui then it can use either the GTK or QT toolkits.
(It's the toolkits that create the buttons/controls/windows/etc. Gambas just uses one of those GUI creating toolkits and they can differ in behaviour when pressing keys/etc)

The code you posted is only really needed on a GTK application. it will probably misbehave for QT as your code will do one thing and the toolkit will do another or repeat what you are doing.

So often what you might find as a "gambas solution" is more like a "toolkit workaround"

So I thought I should add to your post so everyone understands better the finer details and does not use the code if they are using QT :)

If your own program is only for personal use and you do not intend to share it with the world then it will not matter as you will use GTK.
If you intend to share it and use gb.gui then you will need to learn a few things about how the toolkits work slightly differently as somebody trying it may have a QT only system.

gambas uses the systems default toolkit by default and this is generally GTK so you will be programming for GTK behaviour,

Last edit: by BruceSteers

Online now: No Back to the top

Post

Posted
Rating:
#6
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’

gbWilly said

Yogi said

At the moment there is no idea how to change from GTK3 to something else and what is the "best" solution -

Menu Project -> Properties -> Tab components -> deselect gb.gui and select gb.qt5 (or qt6) and click ok

A lot of what you are figuring out and explaining in your first post are basics explained in Gambas Book 1 in detail.
But figuring things out yourself, is my preferred manner of learning as it sticks better 
 

Hi Willy,
Thanks for clarifying.

So my posts here are written after I tried to find a proper solution myself. If it lasts too long to get to the point
I'm here to have some nice chats.
See also my next post to Bruce..

Regards
Yogi
Online now: No Back to the top

Post

Posted
Rating:
#7
Avatar
Enthusiast
Yogi is in the usergroup ‘Enthusiast’

BruceSteers said

Yep.

If your program uses gb.gui then it can use either the GTK or QT toolkits.
(It's the toolkits that create the buttons/controls/windows/etc. Gambas just uses one of those GUI creating toolkits and they can differ in behaviour when pressing keys/etc)

The code you posted is only really needed on a GTK application. it will probably misbehave for QT as your code will do one thing and the toolkit will do another or repeat what you are doing.

So often what you might find as a "gambas solution" is more like a "toolkit workaround"

So I thought I should add to your post so everyone understands better the finer details and does not use the code if they are using QT :)

If your own program is only for personal use and you do not intend to share it with the world then it will not matter as you will use GTK.
If you intend to share it and use gb.gui then you will need to learn a few things about how the toolkits work slightly differently as somebody trying it may have a QT only system.

gambas uses the systems default toolkit by default and this is generally GTK so you will be programming for GTK behaviour,


Hi Bruce,

It's good that you all have an overview, so it's good that I'm writing from this site as a Rookie.
Even if I had read Gambas Part 1 in its entirety, who knows what would be left in my brain.

For me, it's a typical try and error model paired with experience from various programming languages
since the 1980s.

And yes, at the moment there is no idea sharing my unprofessional coding with others. But maybe I should
do it, so it could be corrected 😇

Thanks again,
Regards
Yogi
Online now: No Back to the top
1 guest and 0 members have just viewed this.