Unsolved Changing the QLabel frameshape
-
@Stevolution said in Changing the Qlabel frameshape:
I have a Qlabel set up on my GUI with a frameShape set to Box
How can I turn this frameshape box to NoFrame in my Python routine?Assuming you mean in code:
label.setFrameShape(QtWidgets.QFrame.NoFrame)
-
Hmm... I still have lots to learn
label.setFrameShape(QtWidgets.QFrame.NoFrame) Throws up that I am not using QtWidgets (QWidget?)
label->setFrameStyle(QFrame::Panel | QFrame::Sunken); Throws up a Syntax at the ::
self.AUTOREMOTE.setFrameShape(QFrame::NoFrame). What have I written wrong?
-
self.AUTOREMOTE.setStyleSheet("border: 3px solid black") deletes the entire text and border which I don't understand but hey ho.
Think I need to come up with a different way of doing this
-
@Stevolution said in Changing the Qlabel frameshape:
Throws up a Syntax at the ::
Well, you have to convert it to Python code...
-
@Stevolution said in Changing the Qlabel frameshape:
label.setFrameShape(QtWidgets.QFrame.NoFrame) Throws up that I am not using QtWidgets (QWidget?)
Then show me the constructor line you have in code for creating the
QLabel()
in the first place?QLabel
is also in theQtWidgets
namespace, just asQFrame
is.... -
I have lots to learn here. Please bear with me.
I basically have taken a free piece of code from online that controls servos (via Arduino) and a webcam (Pan and tilt), and I am working my way through making a new GUI for it.
That GUI works, the code compiles.As I work down the code, I am learning what each section achieves/does and annotating it
Might not be the best way to learn, but it is 'kinda' working for me.
self.setWindowTitle('Remote camera') # set window title self.Video = self.ui.Video # The window to display the video feed in # Set up buttons self.QuitButton = self.ui.QuitButton self.PauseButton = self.ui.PauseButton self.UpdateButton = self.ui.UpdateButton # Updates the camera ID self.ConnectButton = self.ui.ConnectButton # Connects the comms self.SysMode_button = self.ui.SysMode_button self.WeaponStatus_button = self.ui.WeaponStatus_button self.IFF_button = self.ui.IFF_button self.Test_button = self.ui.Test_button self.TargetPrf_button = self.ui.TargetPrf_button self.Spectral_button = self.ui.Spectral_button self.TargetSel_button = self.ui.TargetSel_button # Bind buttons self.QuitButton.clicked.connect(self.quit) # Bind quit button to quit method self.PauseButton.clicked.connect(self.toggle_recording) # Bind pause button to pause method self.UpdateButton.clicked.connect(self.update_angles) self.ConnectButton.clicked.connect(self.connect) # Set up LCD displays self.Pan_LCD = self.ui.Pan_LCD self.Tilt_LCD = self.ui.Tilt_LCD self.Ammo_LCD = self.ui.Ammo_LCD self.Time_LCD = self.ui.Time_LCD self.Manual_checkbox = self.ui.Manual_checkbox # Checkbox for manual control self.Manual_checkbox.stateChanged.connect(self.set_manual_mode) # Bind checkbox self.COMlineEdit = self.ui.COMlineEdit # Edit the comms channel box self.CameraIDEdit = self.ui.CameraIDEdit # Camera ID entry box # Labels self.COMConnectLabel = self.ui.COMConnectLabel # Comms connection label self.AUTOREMOTE = self.ui.AUTOREMOTE self.MANOVERRIDE = self.ui.MANOVERRIDE self.SAFE = self.ui.SAFE self.ARMED = self.ui.ARMED self.ENGAGED = self.ui.ENGAGED self.TEST = self.ui.TEST self.INTERROGATE = self.ui.INTERROGATE self.AUTO = self.ui.AUTO self.SELECTIVE = self.ui.SELECTIVE self.INERT = self.ui.INERT self.INFRARED = self.ui.INFRARED self.ULTRASONIC = self.ui.ULTRASONIC
-
@Stevolution
This is a fragment of code which does not address myThen show me the constructor line you have in code for creating the
QLabel()
in the first place?You said my
label.setFrameShape(QtWidgets.QFrame.NoFrame)
Throws up that I am not using QtWidgets (QWidget?)so I can't tell you what to put without knowing how you import your Qt stuff, your relevant
from .. import ...
presumably for PyQt5 or PySide2. -
@JonB said in Changing the Qlabel frameshape:
@Stevolution
This is a fragment of code which does not address myThen show me the constructor line you have in code for creating the
QLabel()
in the first place?You said my
label.setFrameShape(QtWidgets.QFrame.NoFrame)
Throws up that I am not using QtWidgets (QWidget?)so I can't tell you what to put without knowing how you import your Qt stuff, your relevant
from .. import ...
presumably for PyQt5 or PySide2.Sorry - PyQt5
Maybe I should post all the code once I have tidied it a little
-
@Stevolution said in Changing the QLabel frameshape:
Sorry - PyQt5
So, to resolve your "Throws up that I am not using QtWidgets (QWidget?)", if you do not already have this, in the module where you want the line:
label.setFrameShape(QtWidgets.QFrame.NoFrame)
you will need at the top of the file:
from PyQt5 import QtWidgets
(There are slightly different ways you can do what is needed, according to preference, but I don't want to over-complicate for now.)
Damn it, while I'm here, I'd better give you the choices! It's not too hard to understand.
Say you will want to access
QLabel
andQFrame
in a module. You have two ways.from PyQt5 import QtWidgets ... label = QtWidgets.QLabel() label.setFrameShape(QtWidgets.QFrame.NoFrame)
The above way we import just
QtWidgets
, and every time we want to address a widget we have to goQtWidgets.QLabel
,QtWidgets.QFrame
etc.from PyQt5.QtWidgets import QLabel, QFrame, ... ... label = QLabel() label.setFrameShape(QFrame.NoFrame)
The above way we import specific widget classes from
QtWidgets
, and when we want to address a widget we can just goQLabel
,QFrame
etc., not using the leasingQtWidgets.
.Pros/cons for each approach, a matter of personal style/preference.
-
I get an error with that line
NameError: name 'QtWidgets' is not defined
Whats the difference between QtWidgets and QWidget?
import sys # This imports the modules import time from PyQt5.QtWidgets import QApplication, QWidget # PyQy5 is the GUI module. QApplication is part of that module, and QWidget is the Windows interaction class (Keyboard, mouse etc) from PyQt5.QtGui import QIcon, QPixmap, QImage # QImage is a class of PyQt5 that allows image interaction from PyQt5.uic import loadUi import opr # Face tracking Python routine import comm_ard # Python routine to handle the serial communications to the Arduino import random # Random generator import pickle # Allows you to send data between Python scripts using a byte data stream import cv2 # Stands for COMPUTER VISION. Allows the code to take information from a visual source
-
@Stevolution said in Changing the QLabel frameshape:
I get an error with that line
NameError: name 'QtWidgets' is not definedShow me the line you typed, copied & pasted! Since I use
from PyQt5 import QtWidgets
all the time...In the way you now show, it is using my "second approach". You have
from PyQt5.QtWidgets import QApplication, QWidget
so to add references to, say
QLabel
&QFrame
you can either modify to:from PyQt5.QtWidgets import QApplication, QWidget, QLabel, QFrame
or add a brand new line
from PyQt5.QtWidgets import QLabel, QFrame
Don't forget to read what I wrote earlier about when you use this method,
label.setFrameShape(QtWidgets.QFrame.NoFrame)
becomes
label.setFrameShape(QFrame.NoFrame)
Whats the difference between QtWidgets and QWidget?
PyQt5.QtWidgets
is a module (like a namespace if you're familiar with that term). That module contains many classes.QWidget
is a class in the moduleQtWidgets
. That module contains other additional widget-y classes, such asQFrame
. -
@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.