Recent

Author Topic: [qt5] Control contours, transparency  (Read 492 times)

big_M

  • Jr. Member
  • **
  • Posts: 95
[qt5] Control contours, transparency
« on: September 05, 2024, 02:58:10 pm »
I noticed that the contours of some of the controls don't seem to have correct transparent backgrounds / borders when using qt5. When using the default colors this is usually not noticeable, however when one wants to use colorized controls, some of them can look not very nice. Gtk2 doesn't have this problem, or at least not with the controls that I tested.

So, in the pics below, you can see that the contours are fine for:
TEdit, TBitBtn and TStringGrid

However the backgound color goes beyond the border lines and fills the entire rectangle of the control of:
TButton, TMemo and TGroupBox

Is this more likely to be a Lazarus bug or qt5 / breeze bug?
Tested on Lazarus trunk (some months old now), and qt5 5.15 on Linux

zeljko

  • Hero Member
  • *****
  • Posts: 1642
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: [qt5] Control contours, transparency
« Reply #1 on: September 05, 2024, 04:40:29 pm »
That could be theme problem. Try your app with -style fusion.

big_M

  • Jr. Member
  • **
  • Posts: 95
Re: [qt5] Control contours, transparency
« Reply #2 on: September 05, 2024, 09:37:41 pm »
Okay, so a played a bit with it. When using a different style, like fusion, the problem is reduced but not entirely gone. Breeze uses a 1px wide margin around each control, which ideally should be transparent. Fusion does not, so you don't have that problem as much. But it's not gone completely, for example TButton has rounded edges in Fusion, and it still shows the background color on the four corners.

But in any case, I would like to use Breeze for now. So I had a look at the Qt Designer. Here, on some controls it actually behaves the same when I simply change the background color (using style sheet). But I can make it look the way I want when I add "background-clip: padding;" in the style sheet.

So, is there any way to set this style sheet in Lazarus as well?

« Last Edit: September 05, 2024, 09:41:33 pm by big_M »

zeljko

  • Hero Member
  • *****
  • Posts: 1642
    • http://wiki.lazarus.freepascal.org/User:Zeljan
Re: [qt5] Control contours, transparency
« Reply #3 on: September 06, 2024, 08:11:43 am »
Yes, it's possible with TQtWidget(Handle).setStyleSheet() or TQtWidget(BitBtn1.Handle).setStyleSheet() etc...

big_M

  • Jr. Member
  • **
  • Posts: 95
Re: [qt5] Control contours, transparency
« Reply #4 on: September 06, 2024, 11:35:43 am »
It works!  :D

Actually I don't have TQtWidget().setStyleSheet(), but I have TQtWidget().StyleSheet.

So, in order to make it work, one has to make sure to also set the color in the stylesheet, otherwise this will not work.

Code: Pascal  [Select][+][-]
  1. //This will not work. The background is still drawn beyond the border
  2. uses QtWidgets
  3. ...
  4. Memo1.Color:=clGray;
  5. TQtWidget(Memo1.Handle).StyleSheet:='background-clip: padding';
  6.  

Code: Pascal  [Select][+][-]
  1. //This works
  2. uses QtWidgets
  3. ...
  4. TQtWidget(Memo1.Handle).StyleSheet:='background-color: rgb(173, 173, 173);background-clip: padding';
  5.  

Thanks.

big_M

  • Jr. Member
  • **
  • Posts: 95
Re: [qt5] Control contours, transparency
« Reply #5 on: September 06, 2024, 02:22:13 pm »
Ah, unfortunately setting the color with style sheets can override parts of the general styling all together. The better approach for colorizing in qt5 is to use palettes it seems. With palettes the controls get colorized correctly with transparent contours, and additionally the auxiliary colors like borders lines, hovering, highlighting etc get also calculated and set correctly (contrary to simply setting the .Color attribute of a control).

Unfortunately as you said in a different thread, applying palettes to single controls doesn't work. But I think I can live with that for now.


 

TinyPortal © 2005-2018