2

I have used qt designer to make a ui files which I convert using pyuic5. However, the problem I am having is inside qt designer itself.

The problem

The issue I am having is when using the style sheet (set in qt designer) property of 'font-size: 36px' (or any pixel size). When I set this font-size property in the designer, the 'font' property in the designer itself is set to -1 automatically and cannot be changed. This gives the following error while the program is running QFont::setPointSize: Point size <= 0 (-1), must be greater than 0

No problems are encountered while running the program, but the error message appears very frequently which I'd like to avoid.

This answer here suggests removing the font property from the ui files themselves but I would like to avoid this if possible as I am afraid this will cause problems down the line. I have tried clicking on the option to reset the font as it suggests but the button is greyed out (it is already at default but still on -1). The answer here also says it is unrelated to the style sheets but if I remove the font-size from the style sheet the font is no longer stuck at -1. I have confirmed that this happens on different files and it happens when the stylesheet is set.

My question

So, my question is can I fix this error in the qt designer or will I have to remove the font property from my ui files.

Rolv Apneseth
  • 2,078
  • 2
  • 7
  • 19

1 Answers1

2

The fix for my problem is, quite simply, using pt instead of px in the style sheet. Yep, that's it. Now to adjust all my font sizes again.

I don't know why px causes a problem in the qt designer stylesheet so if anybody reading this knows, please do share as I couldn't find an answer for that.

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
Rolv Apneseth
  • 2,078
  • 2
  • 7
  • 19
  • 1
    QtDesigner is limited in many areas to what it understands. Educated guess: QtDesigner tries to be clever about translating your stylesheet into properties. The parser returns -1 for font size because it was supposed to return pt, which it can't. The code that takes its result to rewrite the font property misses a check for -1. Overall, it's a bug and you could file a bug report with the Qt project. My experience with filing bugs with them however is mixed to negative regarding their response (or lack thereof). – ypnos Dec 30 '20 at 16:57
  • If your experience is negative I think I'll leave it but I wanted this here if anyone else happens to be struggling with the same thing as this took me a while to figure out. And yeah your guess is probably right, thanks for replying – Rolv Apneseth Dec 31 '20 at 02:13
  • [@ypnos](https://stackoverflow.com/users/21974/ypnos) someone down voted the question above, but didn't suggest an improvement, do you know how I can improve it in any way? – Rolv Apneseth May 05 '21 at 11:50
  • I don't know, some people just love to do that. I wouldn't spend too much thought onto this. – ypnos May 05 '21 at 22:17
  • Ok, thank you, that was a weird one after 4 months – Rolv Apneseth May 06 '21 at 09:17