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.
  • 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
                • S Stevolution

                  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 Offline
                  jsulmJ Offline
                  jsulm
                  Lifetime Qt Champion
                  wrote on last edited by
                  #28

                  @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?

                  https://forum.qt.io/topic/113070/qt-code-of-conduct

                  S 1 Reply Last reply
                  1
                  • S Stevolution

                    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.

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

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

                    S 1 Reply Last reply
                    1
                    • jsulmJ jsulm

                      @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?

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

                      @jsulm

                      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

                      JonBJ 1 Reply Last reply
                      0
                      • JonBJ JonB

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

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

                        @JonB

                        Where is the code it generates?

                        1 Reply Last reply
                        0
                        • S Stevolution

                          @jsulm

                          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

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

                          @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 via loadUi(). 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 named ui_form.py in your source folder where your form.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:

                          1. Do not use Qt Designer, write the code yourself manually to create widgets dynamically at run-time.

                          2. Use Designer to generate a .ui file. Use PyQt5.uic.loadUi() to load that file dynamically at run-time. No Python code is auto-generated.

                          3. Run PyQt5's pyuic5 executable on the .ui file, generating a ui_....py file with a class/member variables for the elements. import this .py file into yours and access the class methods/variables.

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

                            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

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

                              I import 6 values from a separate Python routine that obtains the serial data from my Arduino (it's a pan/tilt camera with fake gun)

                              self.current_tilt = 0 # Current tilt (info received from arduino and displayed in LCD numbers)
                              self.current_pan = 0 # Current pan (info received from arduino and displayed in LCD numbers)
                              self.ammo_value = 0 # Ammo value (info received from arduino and displayed in LCD numbers)
                              self.time_value = 0 # Time at 100% (info received from arduino and displayed in LCD numbers)
                              self.tmp_value = 0 # Temp level (info received from arduino and displayed on ProgressBar)
                              self.rpm_value = 0 # Rounds per minute (info received from arduino and displayed on ProgressBar)

                              If I print these imported values, they print out fine and track the changing values as they arrive from the Arduino.

                              print(self.current_pan)
                              print(self.current_tilt)
                              print(self.ammo_value)
                              print(self.time_value)
                              print(self.tmp_value)
                              print(self.rpm_value)

                              However, when I go to use these variables, two of them are causing an issue.

                              self.Pan_LCD.display(self.current_pan) # All these values are retrieved in Comm_ard.py
                              self.Tilt_LCD.display(self.current_tilt)
                              self.Ammo_LCD.display(self.ammo_value)
                              self.Time_LCD.display(self.time_value)
                              self.Temp_bar.setValue(self.tmp_value)
                              self.Rounds_bar.setValue(self.rpm_value)

                              The top 4 LCD.display lines work fine. But, the bottom 2 updates for the ProgressBar create an exception error (Error split data : 6) in the Comm_ard.py routine.

                              I don't understand how it can print the correct variable, yet using it causes a problem?

                              If I use one of the 2 troublesome variables in the LCD update lines instead... it works. So that leads me to believe that all the variables are fine and this is an update to the ProgressBar problem.

                              Could it be a timing issue? (messing up the serial comms). Edit. Checked this.... don't think so

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

                                Ah the joys of programming...

                                For some reason, it needs to be stated as an int:

                                self.Temp_bar.setValue(int(self.tmp_value))

                                This works

                                JonBJ 1 Reply Last reply
                                0
                                • S Stevolution

                                  Ah the joys of programming...

                                  For some reason, it needs to be stated as an int:

                                  self.Temp_bar.setValue(int(self.tmp_value))

                                  This works

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

                                  @Stevolution
                                  I was about to tell you this :)

                                  Ah the joys of programming...

                                  This is (probably) from the "joys" of programming in Python. Unlike, say, C++ it's not a rigorously typed language, and that can lead to problems with type conversion.

                                  I'm not sure why it did not implicitly convert your self.tmp_value to int, you would have to show exactly what was in self.tmp_value. And I don't know how/why calling a QProgressBar.setValue() seems to cause an issue in some arduino code.

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

                                    Yes it is odd. They are all ints.... counting in 1's from 0. Doesn't seem to matter to the LCD lines, but the ProgressBar complained.

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

                                      Forgive the varying questions, but they are on a theme (as in - same project).

                                      I want to flash a Qlabel on and off. How can I achieve that? (I know the code to actually make it go on and off)

                                      I tried Qtimer, but my routine really doesn't like that. Probably my bad implementation of it.

                                      My (probably bad) idea was:

                                      def LowAmmo(self):
                                      
                                          if (int(self.ammo_value<50)) and (self.is_connected):
                                              self.Ammo_flash +=1
                                      
                                              if self.Ammo_flash == 50:
                                                   self.Critical_centre.setStyleSheet("QLabel {background-color: black; color: rgb(255, 209, 42);}");
                                                   self.Critical_border.setFrameShape(QFrame.NoFrame)
                                      
                                              elif self.Ammo_flash>100:
                                                  self.Ammo_flash = 0 
                                                  self.Critical_centre.setStyleSheet("QLabel {background-color: rgb(255, 209, 42); color: black;}");
                                                  self.Critical_border.setFrameShape(QFrame.Box)
                                      

                                      Trouble is, what calls self.LowAmmo() ? This routine never gets checked.
                                      If I throw this code in somewhere else (like the routine where it displays the ammo value on the LCD), it throws up this damn Error split data : 6 error again.

                                      Still don't understand that error or what creates it

                                      JonBJ 1 Reply Last reply
                                      0
                                      • S Stevolution

                                        Forgive the varying questions, but they are on a theme (as in - same project).

                                        I want to flash a Qlabel on and off. How can I achieve that? (I know the code to actually make it go on and off)

                                        I tried Qtimer, but my routine really doesn't like that. Probably my bad implementation of it.

                                        My (probably bad) idea was:

                                        def LowAmmo(self):
                                        
                                            if (int(self.ammo_value<50)) and (self.is_connected):
                                                self.Ammo_flash +=1
                                        
                                                if self.Ammo_flash == 50:
                                                     self.Critical_centre.setStyleSheet("QLabel {background-color: black; color: rgb(255, 209, 42);}");
                                                     self.Critical_border.setFrameShape(QFrame.NoFrame)
                                        
                                                elif self.Ammo_flash>100:
                                                    self.Ammo_flash = 0 
                                                    self.Critical_centre.setStyleSheet("QLabel {background-color: rgb(255, 209, 42); color: black;}");
                                                    self.Critical_border.setFrameShape(QFrame.Box)
                                        

                                        Trouble is, what calls self.LowAmmo() ? This routine never gets checked.
                                        If I throw this code in somewhere else (like the routine where it displays the ammo value on the LCD), it throws up this damn Error split data : 6 error again.

                                        Still don't understand that error or what creates it

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

                                        @Stevolution

                                        tried Qtimer, but my routine really doesn't like that. Probably my bad implementation of it.
                                        Trouble is, what calls self.LowAmmo() ? This routine never gets checked.

                                        You do indeed need to use QTimer to call LowAmmo() periodically.

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

                                          Thanks. That is what I have done.
                                          Also worked out the issue with the Split data error... Int issue somewhere else

                                          1 Reply 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