Unsolved Changing the QLabel frameshape
-
@JonB said in Changing the QLabel frameshape:
PyQt5.QtWidgets import QApplication, QWidget, QLabel, QFrame
PyQt5.QtWidgets import QApplication, QWidget, QLabel, QFrame has fixed the issue.
I didn't realise I needed to add those to the declared list.Thank you very much for your time and patience
-
@Stevolution
As I wrote earlier, if you go for thefrom PyQt5.QtWidgets import Q...
route, which is fine, you must now add to that list each time you want to access a specific class, likeQWidget
orQFrame
orQPushButton
, and then you can address those by their plain class name,QWidget
orQFrame
, instead ofQtWidgets.QWidget
,QtWidgets.QFrame
etc.You may also shortcut having to spell out each class name by going
from PyQt5.QtWidgets import *
This imports as
QWidget
,QFrame
,QPushButton
and everything else (non-underscore) in theQtWidgets
module, in one go. However, this is usually regarded as poor Python practice [https://docs.python.org/3/tutorial/modules.html]. -
Yes. Many thanks for your excellent assistance
-
Without appearing to be totally thick... it's frustrating that I have sorted out all the comms to the Arduino, camera importing etc...
but cannot get my head around this formatting to change text properties.
How would I change the font size of a label? All my efforts have failed.
I had to import the class QFrame to change the frame, but QFont gives a syntaxThis is clearly wrong...
self.COMConnectLabel.setFontSize(14);
-
I think I need to walk away for a while. Made great progress today....
But still can't change that text font size!
-
@Stevolution Thank you Denni. I will have another look at that in a while.
Just trying to work out why my routine is throwing up an exception when I transfer 6 bytes of data from my Arduino to my Python process.
I can print all six bytes correctly in the decoding routine (called Comm_ard.py), but when I use bytes 5 or 6 in the Python code, it throws up an exception error. Hmm
-
OK. Fixed the exception issue.
NOTHING I try will let me change the font size. Spent so much time on this. You suggestions Denni didin't work.
It's clearly me, but no idea what I am doing wrong. Declared QFont at the start etc.It's maddening how something so stupid takes so long
-
Yes, but I need to implement it in my code. That is a lot of code just to change a font size! Thank you Denni... I do appreciate it.
I don't really understand why it's so complicated. Why can you not just say: self.COMConnectLabel.setFontSize(14);
Anyway, I will sort it out
-
That is a lot of code just to change a font size!
I don't really understand why it's so complicated. Why can you not just say:self.COMConnectLabel.setFontSize(14);
You only need the lines @Denni-0 gave you earlier:
MyFont = QFont() MyFont.setPointSize(14) MyLabel = QLabel() MyLabel.setFont(MyFont)
That's 3 lines to change the label's font. That's just what calls Qt has provided. If you wanted to be able to go
self.COMConnectLabel.setFontSize(14)
you could subclass your labels to addsetFontSize(size)
as an available method. -
S0..
MyFont = QFont() MyFont.setPointSize(18) self.COMConnectLabel = QLabel() self.COMConnectLabel.setFont(MyFont)
This freezes my routine
-
Ha ... thanks Denni
Yes, using QT Designer. Got nearly everything working except this and a ProgressBar that keeps throwing up an exception.I will see if I can make a smaller bit of code and either get it working, or post it for your advice.
Thanks -
Thanks Denni, that is a very kind offer.
The reason I started with QT Designer, is I started with a project that someone else designed using QT Designer, and I have adapted it to my needs.
I don't know Python. I have come from Arduino programming and its pretty different.I have reverse engineered the code, and made far more progress than I thought I would have in a few days.
I have some fundamental issue somewhere. I have links to the labels, tick boxes, buttons etc all working fine.
But, I just cannot get the font size to change or the ProgressBar to work.
-
GOT IT
font = self.COMConnectLabel.font() font.setPointSize(14) self.COMConnectLabel.setFont(font)
This worked. Trial and error.
Now it I need to fix the progress bar
-
Right, the problem with the progressbar is the co-ords.
In QT Designer, it shows 480,60 20x191 as the co-ords for the Progressbar
But i declare:
self.Temp_bar = QProgressBar(self) self.Temp_bar.setGeometry(480, 60, 20 , 191) self.Temp_bar.setValue(350)
and the Progress bar is way off the screen (so it was working - just not visible).
The actual co-ords to get it anywhere near the position in QT Designer are (502, 820, 50 , 191) And they are not exact.
Also, its going from top to bottom instead of as stated in QT Designer, and it's the wrong colour.So... have I made my own progress bar that has nothing to do with the design I made in QT Designer, or and I missing something that links them together? Hmm
Edit/update.
OK, its all incorrect. From what I understand, for some reason... all the settings in QT Designer are lost.
I would need to set up a new style sheet to reproduce the one I made in QT Designer. That seems pointless.Is there a simpler way to directly draw a progressbar style 'box' that goes vertically up the screen dependant on a variable (I know there will be... I just don't know it yet).
I do have to say the mixed/incorrect/random information about implementing these functions in QT Designer is very frustrating.
-
@Stevolution said in Changing the QLabel frameshape:
In QT Designer, it shows 480,60 20x191 as the co-ords for the Progressbar
But i declare:One moment: you have one progress bar in designer, but then you add one in code? Why don't you use the one from designer?
-
@Stevolution
Just to say: there is absolutely nothing wrong with using Qt Designer to design your UI, and auto-generate the Python code which implements it, as you have been doing. The code it generates is easy to understand (if you choose to look at it, you don't have to), and essentially does what you would have to do yourself if you choose to do it manually instead. Especially if you are a beginner, it can ease you into Qt programming without having to learn everything about the classes from the outset. As you have discovered, you can mix static design-time elements with dynamically-created run-time elements as you please.Plenty of other toolsets have a visual designer as well as run-time coding. It is largely a matter of personal preference which you choose to use, and there are pros & cons of each approach. Many, but not all, Qt developers use Designer. This applies whether you use C++ or Python. So feel free to follow your chosen path either way.
-
Well this is what I am trying to learn. This is my first Python code attempt!
How do I access the one I designed in QT Designer? Googling shows examples such as the one I posted/used, but as you say... I think I have made another progress bar, rather than manage to access the one I made in QT Designer.
My QT Designer progress bar is called Temp_bar, so I am not sure why it is not accessing it.
If I don't state the setGeometry, then I cannot see any ProgressBar -
Where is the code it generates?
-
@Stevolution
I don't know what you called your design-time progress bar, but you go:self.Temp_bar = QProgressBar(self)
As @jsulm said, here you are simply creating your own dynamic, run-time progress bar. If you already have one from designer you should use that one, no
... = QProgressBar(self)
in your own code.For the code it generates:
-
I see you have
from PyQt5.uic import loadUi
. So I'm thinking you have chosen not to generate code, you just load the.ui
dynamically at run-time vialoadUi()
. In that case, no Python code is being generated, so there is no source code to look at. -
You could change to using
pyuic5
, which you run whenever you change the Designer.ui
file content to generate a Python class code from it. In that case, you would find it creates a file namedui_form.py
in your source folder where yourform.ui
file is.
Have a read of e.g. https://stackoverflow.com/a/52471945/489865 for the pros & cons of each.
See https://www.riverbankcomputing.com/static/Docs/PyQt5/designer.html for the various choices.
So to summarise, you have 3 choices for how to do your UI code:
-
Do not use Qt Designer, write the code yourself manually to create widgets dynamically at run-time.
-
Use Designer to generate a
.ui
file. UsePyQt5.uic.loadUi()
to load that file dynamically at run-time. No Python code is auto-generated. -
Run PyQt5's
pyuic5
executable on the.ui
file, generating aui_....py
file with a class/member variables for the elements.import
this.py
file into yours and access the class methods/variables.
-
-
OK. Thank you. self.Temp_bar = self.ui.Temp_bar brought the Progressbar up that I designed immediately.
This is the part I have been struggling with, as I have found the wealth of information regarding these features on the web... difficult to wade through at best.
Still learning, but you guys have been super helpful. Thank you for your valuable time