Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Changing the QLabel frameshape
Forum Updated to NodeBB v4.3 + New Features

Changing the QLabel frameshape

Scheduled Pinned Locked Moved Unsolved Qt for Python
42 Posts 4 Posters 11.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • JonBJ JonB

    @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 the QtWidgets namespace, just as QFrame is....

    S Offline
    S Offline
    Stevolution
    wrote on last edited by Stevolution
    #8

    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
    
    JonBJ 1 Reply Last reply
    0
    • S Stevolution

      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
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #9

      @Stevolution
      This is a fragment of code which does not address my

      Then 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.

      S 1 Reply Last reply
      0
      • JonBJ JonB

        @Stevolution
        This is a fragment of code which does not address my

        Then 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.

        S Offline
        S Offline
        Stevolution
        wrote on last edited by Stevolution
        #10

        @JonB said in Changing the Qlabel frameshape:

        @Stevolution
        This is a fragment of code which does not address my

        Then 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

        JonBJ 1 Reply Last reply
        0
        • S Stevolution

          @JonB said in Changing the Qlabel frameshape:

          @Stevolution
          This is a fragment of code which does not address my

          Then 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

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #11

          @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 and QFrame 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 go QtWidgets.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 go QLabel, QFrame etc., not using the leasing QtWidgets..

          Pros/cons for each approach, a matter of personal style/preference.

          S 1 Reply Last reply
          1
          • JonBJ JonB

            @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 and QFrame 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 go QtWidgets.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 go QLabel, QFrame etc., not using the leasing QtWidgets..

            Pros/cons for each approach, a matter of personal style/preference.

            S Offline
            S Offline
            Stevolution
            wrote on last edited by Stevolution
            #12

            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
            
            JonBJ 1 Reply Last reply
            0
            • S Stevolution

              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
              
              JonBJ Offline
              JonBJ Offline
              JonB
              wrote on last edited by JonB
              #13

              @Stevolution said in Changing the QLabel frameshape:

              I get an error with that line
              NameError: name 'QtWidgets' is not defined

              Show 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 module QtWidgets. That module contains other additional widget-y classes, such as QFrame.

              S 1 Reply Last reply
              1
              • JonBJ JonB

                @Stevolution said in Changing the QLabel frameshape:

                I get an error with that line
                NameError: name 'QtWidgets' is not defined

                Show 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 module QtWidgets. That module contains other additional widget-y classes, such as QFrame.

                S Offline
                S Offline
                Stevolution
                wrote on last edited by
                #14

                @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

                JonBJ 1 Reply Last reply
                0
                • S Stevolution

                  @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

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #15

                  @Stevolution
                  As I wrote earlier, if you go for the from PyQt5.QtWidgets import Q... route, which is fine, you must now add to that list each time you want to access a specific class, like QWidget or QFrame or QPushButton, and then you can address those by their plain class name, QWidget or QFrame, instead of QtWidgets.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 the QtWidgets module, in one go. However, this is usually regarded as poor Python practice [https://docs.python.org/3/tutorial/modules.html].

                  1 Reply Last reply
                  1
                  • S Offline
                    S Offline
                    Stevolution
                    wrote on last edited by
                    #16

                    Yes. Many thanks for your excellent assistance

                    1 Reply Last reply
                    0
                    • S Offline
                      S Offline
                      Stevolution
                      wrote on last edited by
                      #17

                      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 syntax

                      This is clearly wrong...

                      self.COMConnectLabel.setFontSize(14);

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        Stevolution
                        wrote on last edited by
                        #18

                        I think I need to walk away for a while. Made great progress today....

                        But still can't change that text font size!

                        S 1 Reply Last reply
                        0
                        • S Stevolution

                          I think I need to walk away for a while. Made great progress today....

                          But still can't change that text font size!

                          S Offline
                          S Offline
                          Stevolution
                          wrote on last edited by
                          #19

                          @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

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            Stevolution
                            wrote on last edited by Stevolution
                            #20

                            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

                            1 Reply Last reply
                            0
                            • S Offline
                              S Offline
                              Stevolution
                              wrote on last edited by
                              #21

                              @Denni-0

                              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

                              JonBJ 1 Reply Last reply
                              0
                              • S Stevolution

                                @Denni-0

                                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

                                JonBJ Offline
                                JonBJ Offline
                                JonB
                                wrote on last edited by JonB
                                #22

                                @Stevolution

                                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 add setFontSize(size) as an available method.

                                1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  Stevolution
                                  wrote on last edited by
                                  #23

                                  S0..

                                          MyFont = QFont()
                                          MyFont.setPointSize(18)
                                  
                                          self.COMConnectLabel = QLabel()
                                          self.COMConnectLabel.setFont(MyFont)
                                  

                                  This freezes my routine

                                  1 Reply Last reply
                                  0
                                  • S Offline
                                    S Offline
                                    Stevolution
                                    wrote on last edited by
                                    #24

                                    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

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      Stevolution
                                      wrote on last edited by
                                      #25

                                      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.

                                      1 Reply Last reply
                                      0
                                      • S Offline
                                        S Offline
                                        Stevolution
                                        wrote on last edited by
                                        #26

                                        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

                                        1 Reply Last reply
                                        1
                                        • S Offline
                                          S Offline
                                          Stevolution
                                          wrote on last edited by Stevolution
                                          #27

                                          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.

                                          jsulmJ JonBJ 2 Replies Last reply
                                          0

                                          • Login

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular
                                          • Users
                                          • Groups
                                          • Search
                                          • Get Qt Extensions
                                          • Unsolved