Gtk Button Theming 'suggested-action' and 'destructive-action'
Gtk Button Theming 'suggested-action' and 'destructive-action'
In Gambas, how do I define a button to be themed as 'destructive-action' or 'suggested-action'? They should be of different color.
- cogier
- Site Admin
- Posts: 1127
- Joined: Wednesday 21st September 2016 2:22pm
- Location: Guernsey, Channel Islands
Re: Gtk Button Theming 'suggested-action' and 'destructive-action'
The best way is to make your own bespoke button. Run this code in a new Graphical Application.In Gambas, how do I define a button to be themed as 'destructive-action' or 'suggested-action'? They should be of different color.
PanelButton As Panel
Label1 As Label
Public Sub Form_Open()
With Me
.Center
.Y = 250
.Height = 75
.Width = 300
End With
With PanelButton = New Panel(Me) As "PanelButton"
.Height = 56
.Width = 100
.Arrangement = Arrange.Vertical
.Background = Color.Yellow
.Border = Border.Raised
End With
With Label1 = New Label(PanelButton) As "Label1"
.Expand = True
.Font.Size = 18
.Font.Bold = True
.Foreground = Color.Red
.Alignment = Align.Center
.Text = "Destructive-action!!"
End With
End
Public Sub Label1_MouseDown()
PanelButton.Border = Border.Sunken
End
Public Sub Label1_MouseUp()
Message.Warning("This computer will now crash in a fountain of your code!", "OK")
PanelButton.Border = Border.Raised
End
Re: Gtk Button Theming 'suggested-action' and 'destructive-action'
I appreaciate the humour
Re: Gtk Button Theming 'suggested-action' and 'destructive-action'
Forgive me, but I do not quite understand what you want to achieve.
Europaeus sum !
Amare memorentes atque deflentes ad mortem silenter labimur.
Amare memorentes atque deflentes ad mortem silenter labimur.
Re: Gtk Button Theming 'suggested-action' and 'destructive-action'
Here's a screenshot illustrating the use of suggested-action style class. On the screenshot I am closing an unsaved document in the xed text editor and the program highlights the "Save As..." button. Gtk Inspector reveals that the button has a suggested-action css style class associated to it. The color in this case is defined in /usr/share/themes/Mint-Yz-Base-Purple/gtk-3.0/gtk.css
PS: I'm using Linux Mint and SebastJava/mint-yz-theme here.
PSS: Maybe this could be achieved in QT as well as in Gtk. I can change my app to using QT. I know you vuott are using QT if I remember correctly from an earlier post.
I wan't a specific button on my gambas app to be styled like this. I don't want to hardcode the background. I want the appearance to follow which ever theme the user has specified on their gnu/linux.PS: I'm using Linux Mint and SebastJava/mint-yz-theme here.
PSS: Maybe this could be achieved in QT as well as in Gtk. I can change my app to using QT. I know you vuott are using QT if I remember correctly from an earlier post.
- BruceSteers
- Posts: 1582
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Gtk Button Theming 'suggested-action' and 'destructive-action'
You can set a buttons Cancel or Default Boolean properties.
btnSaveAs.Default = True
btnExit.Cancel = True
btnSaveAs.Default = True
btnExit.Cancel = True
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: Gtk Button Theming 'suggested-action' and 'destructive-action'
I tried default and cancel but they don't change the appearance - At least on my setup.BruceSteers wrote: ↑Saturday 9th September 2023 9:57pm You can set a buttons Cancel or Default Boolean properties.
btnSaveAs.Default = True
btnExit.Cancel = True
I will post a new question about theming QT apps.
- BruceSteers
- Posts: 1582
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Gtk Button Theming 'suggested-action' and 'destructive-action'
It's down to the theme config.
You have to code it yourself if you want it guaranteed.
You have to code it yourself if you want it guaranteed.
If at first you don't succeed , try doing something differently.
BruceS
BruceS
Re: Gtk Button Theming 'suggested-action' and 'destructive-action'
How should I theme config for a Gambas app?
There seems to be something odd with naming convention of gtk ui elements in Gambas. Here's a screenshot showcasing my image viewer prototype made in Gambas as a GTK+3 Application. For example Gtk Inspector reveals that the proggressbar is called GtkFixed - Which makes it impossible to be themed? I would have expected it to be called GtkProggressBar and have the name ProgressBar1 shown aswell - As compared to gtk3-widget-factory on the right side on the screenshot. Is it possible that proggressbar is not a native gtk component in Gambas?
- BruceSteers
- Posts: 1582
- Joined: Thursday 23rd July 2020 5:20pm
- Location: Isle of Wight
- Contact:
Re: Gtk Button Theming 'suggested-action' and 'destructive-action'
You'd have to ask Benoit about that level of internal detail.
Personally i think it would be easier to just make your own buttons like cogier first suggested.
I'd probably do something like this....
Save this code in my projects .src folder as Form.class
That will make ALL your programs windows buttons (including modal windows like Message.class) show a hint of green if Default or a hint of red if Cancel.
of course you can change the color to your own liking
PS. you need to explicitly use Me.Show in your startup forms Form_Open() method as it does not seem to run Show() itself.
Personally i think it would be easier to just make your own buttons like cogier first suggested.
I'd probably do something like this....
Save this code in my projects .src folder as Form.class
' Gambas class file
Create Static
Export
Public Sub Show()
SetButtonColors
Super.Show()
End
Public Sub ShowModal() As Integer
SetButtonColors
Return Super.ShowModal()
End
Private Sub SetButtonColors()
Dim b As Button
For Each c As Control In Me.Controls
If c Is Button Then
b = c
If b.Default Then b.Background = Color.SetAlpha(Color.Green, 220)
If b.Cancel Then b.Background = Color.SetAlpha(Color.Red, 220)
Endif
Next
End
That will make ALL your programs windows buttons (including modal windows like Message.class) show a hint of green if Default or a hint of red if Cancel.
of course you can change the color to your own liking
PS. you need to explicitly use Me.Show in your startup forms Form_Open() method as it does not seem to run Show() itself.
If at first you don't succeed , try doing something differently.
BruceS
BruceS