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. Expanding Weirdness
Forum Updated to NodeBB v4.3 + New Features

Expanding Weirdness

Scheduled Pinned Locked Moved Solved Qt for Python
5 Posts 3 Posters 640 Views 2 Watching
  • 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.
  • H Offline
    H Offline
    Hexrin
    wrote on last edited by Hexrin
    #1

    Hi,
    So I'm having an issue where a QTextBox is getting cut off after a certain point of expanding. It seems to be acting like it has some kind of maximum width despite me never setting a maximum width. Here is my code:

    from pyqtgraph import QtCore, QtGui
    import sys
    from sensor_msgs.msg import Imu, MagneticField, NavSatFix
    from PyQt5 import QtCore, QtGui
    from PyQt5.QtCore import Qt
    import numpy as np
    import sys
    
    class statusUI(QtGui.QPushButton):
        
    	def __init__(self):
            
    		QtGui.QPushButton.__init__(self)
    	
    		#set the widget's height
    		self.setFixedHeight(200)
    
    		statusUILayout = QtGui.QHBoxLayout(self)
    
    		self.scrollArea = dataScrollArea()
    		statusUILayout.addWidget(self.scrollArea)
    
    		self.setUpMagUI()
    
    	def setUpMagUI(self):
    
    		#create mag labels
    		self.magneticFieldCovNameLabel = QtGui.QLabel("Magnetic Field Covariance: ")
    		self.magneticFieldCovNumberLabel = QtGui.QLabel(str([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]).translate(None, "'"))
    
    		self.magneticFieldCovNameLabel.setAlignment(Qt.AlignLeft)
    		self.magneticFieldCovNumberLabel.setAlignment(Qt.AlignLeft)
    
    		self.scrollArea.addLine(self.magneticFieldCovNameLabel, self.magneticFieldCovNumberLabel)
    
    		self.scrollArea.addStretch()
    
    class dataScrollArea(QtGui.QScrollArea):
    
    	def __init__(self):
    
    		QtGui.QScrollArea.__init__(self)
    
    		self.setWidgetResizable(True)
    
    		# making qwidget object
    		content = QtGui.QWidget(self)
    		self.setWidget(content)
    
    		self.statusesLayout = QtGui.QVBoxLayout(content)
    		self.scrollbar = self.verticalScrollBar()
    
    	def addLine(self, widget1, widget2):
    
    		lineWidget = QtGui.QFrame()
    		lineWidget.setFrameStyle(QtGui.QFrame.StyledPanel)
    		lineLayout = QtGui.QHBoxLayout()
    		lineWidget.setLayout(lineLayout)
    		lineLayout.setAlignment(Qt.AlignLeft)
    		lineLayout.addWidget(widget1)
    		lineLayout.addWidget(widget2)
    		self.statusesLayout.addWidget(lineWidget)
    		widget2.setWordWrap(True)
    
    	def addStretch(self):
    
    		self.statusesLayout.addStretch()
    
    app = QtGui.QApplication(sys.argv)
    main = QtGui.QWidget()
    layout = QtGui.QHBoxLayout(main)
    main.show()
    testWidget = QtGui.QHBoxLayout()
    layout.addWidget(statusUI())
    sys.exit(app.exec_())
    

    It seems to start expanding just fine.
    Screenshot from 2021-08-04 13-22-32.png

    But when I get to the last 0.000, it starts to take a lot more space than it usually would when expanding...
    Screenshot from 2021-08-04 13-23-31.png

    And then it just cuts off the last 0.000 for some reason.
    Screenshot from 2021-08-04 13-23-46.png

    Can someone tell me why this is happening? Thanks for any help!
    I think I'm using PyQt5, although I have to import from pyqtgraph else it doesn't work for some reason.

    eyllanescE 1 Reply Last reply
    0
    • H Hexrin

      Hi,
      So I'm having an issue where a QTextBox is getting cut off after a certain point of expanding. It seems to be acting like it has some kind of maximum width despite me never setting a maximum width. Here is my code:

      from pyqtgraph import QtCore, QtGui
      import sys
      from sensor_msgs.msg import Imu, MagneticField, NavSatFix
      from PyQt5 import QtCore, QtGui
      from PyQt5.QtCore import Qt
      import numpy as np
      import sys
      
      class statusUI(QtGui.QPushButton):
          
      	def __init__(self):
              
      		QtGui.QPushButton.__init__(self)
      	
      		#set the widget's height
      		self.setFixedHeight(200)
      
      		statusUILayout = QtGui.QHBoxLayout(self)
      
      		self.scrollArea = dataScrollArea()
      		statusUILayout.addWidget(self.scrollArea)
      
      		self.setUpMagUI()
      
      	def setUpMagUI(self):
      
      		#create mag labels
      		self.magneticFieldCovNameLabel = QtGui.QLabel("Magnetic Field Covariance: ")
      		self.magneticFieldCovNumberLabel = QtGui.QLabel(str([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]).translate(None, "'"))
      
      		self.magneticFieldCovNameLabel.setAlignment(Qt.AlignLeft)
      		self.magneticFieldCovNumberLabel.setAlignment(Qt.AlignLeft)
      
      		self.scrollArea.addLine(self.magneticFieldCovNameLabel, self.magneticFieldCovNumberLabel)
      
      		self.scrollArea.addStretch()
      
      class dataScrollArea(QtGui.QScrollArea):
      
      	def __init__(self):
      
      		QtGui.QScrollArea.__init__(self)
      
      		self.setWidgetResizable(True)
      
      		# making qwidget object
      		content = QtGui.QWidget(self)
      		self.setWidget(content)
      
      		self.statusesLayout = QtGui.QVBoxLayout(content)
      		self.scrollbar = self.verticalScrollBar()
      
      	def addLine(self, widget1, widget2):
      
      		lineWidget = QtGui.QFrame()
      		lineWidget.setFrameStyle(QtGui.QFrame.StyledPanel)
      		lineLayout = QtGui.QHBoxLayout()
      		lineWidget.setLayout(lineLayout)
      		lineLayout.setAlignment(Qt.AlignLeft)
      		lineLayout.addWidget(widget1)
      		lineLayout.addWidget(widget2)
      		self.statusesLayout.addWidget(lineWidget)
      		widget2.setWordWrap(True)
      
      	def addStretch(self):
      
      		self.statusesLayout.addStretch()
      
      app = QtGui.QApplication(sys.argv)
      main = QtGui.QWidget()
      layout = QtGui.QHBoxLayout(main)
      main.show()
      testWidget = QtGui.QHBoxLayout()
      layout.addWidget(statusUI())
      sys.exit(app.exec_())
      

      It seems to start expanding just fine.
      Screenshot from 2021-08-04 13-22-32.png

      But when I get to the last 0.000, it starts to take a lot more space than it usually would when expanding...
      Screenshot from 2021-08-04 13-23-31.png

      And then it just cuts off the last 0.000 for some reason.
      Screenshot from 2021-08-04 13-23-46.png

      Can someone tell me why this is happening? Thanks for any help!
      I think I'm using PyQt5, although I have to import from pyqtgraph else it doesn't work for some reason.

      eyllanescE Offline
      eyllanescE Offline
      eyllanesc
      wrote on last edited by eyllanesc
      #4

      @Hexrin The problem is mainly caused by the line lineLayout.setAlignment(Qt.AlignLeft) that you probably used so that the first column occupies the minimum space but also makes the second column compress. Instead I use stretch factors.

      import sys
      
      from pyqtgraph import QtCore, QtGui
      
      
      class statusUI(QtGui.QPushButton):
          def __init__(self):
              QtGui.QPushButton.__init__(self)
              self.setMinimumHeight(200)
              statusUILayout = QtGui.QHBoxLayout(self)
              self.scrollArea = dataScrollArea()
              statusUILayout.addWidget(self.scrollArea)
      
              self.setUpMagUI()
      
          def setUpMagUI(self):
              text = str(
                  [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
              ).translate({None: "'"})
      
              self.magneticFieldCovNameLabel = QtGui.QLabel("Magnetic Field Covariance: ")
              self.magneticFieldCovNumberLabel = QtGui.QLabel(text)
      
              self.magneticFieldCovNameLabel.setAlignment(QtCore.Qt.AlignLeft)
              self.magneticFieldCovNumberLabel.setAlignment(QtCore.Qt.AlignLeft)
      
              self.scrollArea.addLine(
                  self.magneticFieldCovNameLabel, self.magneticFieldCovNumberLabel
              )
      
              self.scrollArea.addStretch()
      
      
      class dataScrollArea(QtGui.QScrollArea):
          def __init__(self):
              QtGui.QScrollArea.__init__(self)
              self.setWidgetResizable(True)
              content = QtGui.QWidget()
              self.setWidget(content)
              self.statusesLayout = QtGui.QVBoxLayout(content)
      
          def addLine(self, widget1, widget2):
              widget2.setWordWrap(True)
              lineWidget = QtGui.QFrame()
              lineLayout = QtGui.QHBoxLayout(lineWidget)
              lineWidget.setLayout(lineLayout)
              lineLayout.addWidget(widget1)
              lineLayout.addWidget(widget2, stretch=1)
              self.statusesLayout.addWidget(lineWidget)
      
          def addStretch(self):
              self.statusesLayout.addStretch()
      
      app = QtGui.QApplication(sys.argv)
      main = QtGui.QWidget()
      main.resize(640, 480)
      layout = QtGui.QHBoxLayout(main)
      main.show()
      testWidget = QtGui.QHBoxLayout()
      layout.addWidget(statusUI())
      sys.exit(app.exec_())
      

      Output:

      Screenshot_20210804_160510.png

      Screenshot_20210804_160520.png

      Please for a next time remove unnecessary imports and also note that from pyqtgraph import QtCore, QtGui and from PyQt5 import QtCore, QtGui may conflict causing silent bugs.

      If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

      H 1 Reply Last reply
      2
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        Please reduce your script to a minimal reproducible case.

        One main thing is that your statusUI widget is given way to much information about its parent and layout. That's not its role to insert itself in some layout. This is something for the widget creating a statusUI to handle.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        H 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          Please reduce your script to a minimal reproducible case.

          One main thing is that your statusUI widget is given way to much information about its parent and layout. That's not its role to insert itself in some layout. This is something for the widget creating a statusUI to handle.

          H Offline
          H Offline
          Hexrin
          wrote on last edited by
          #3

          @SGaist I've updated my post. I hope it's a bit more readable now.

          1 Reply Last reply
          0
          • H Hexrin

            Hi,
            So I'm having an issue where a QTextBox is getting cut off after a certain point of expanding. It seems to be acting like it has some kind of maximum width despite me never setting a maximum width. Here is my code:

            from pyqtgraph import QtCore, QtGui
            import sys
            from sensor_msgs.msg import Imu, MagneticField, NavSatFix
            from PyQt5 import QtCore, QtGui
            from PyQt5.QtCore import Qt
            import numpy as np
            import sys
            
            class statusUI(QtGui.QPushButton):
                
            	def __init__(self):
                    
            		QtGui.QPushButton.__init__(self)
            	
            		#set the widget's height
            		self.setFixedHeight(200)
            
            		statusUILayout = QtGui.QHBoxLayout(self)
            
            		self.scrollArea = dataScrollArea()
            		statusUILayout.addWidget(self.scrollArea)
            
            		self.setUpMagUI()
            
            	def setUpMagUI(self):
            
            		#create mag labels
            		self.magneticFieldCovNameLabel = QtGui.QLabel("Magnetic Field Covariance: ")
            		self.magneticFieldCovNumberLabel = QtGui.QLabel(str([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]).translate(None, "'"))
            
            		self.magneticFieldCovNameLabel.setAlignment(Qt.AlignLeft)
            		self.magneticFieldCovNumberLabel.setAlignment(Qt.AlignLeft)
            
            		self.scrollArea.addLine(self.magneticFieldCovNameLabel, self.magneticFieldCovNumberLabel)
            
            		self.scrollArea.addStretch()
            
            class dataScrollArea(QtGui.QScrollArea):
            
            	def __init__(self):
            
            		QtGui.QScrollArea.__init__(self)
            
            		self.setWidgetResizable(True)
            
            		# making qwidget object
            		content = QtGui.QWidget(self)
            		self.setWidget(content)
            
            		self.statusesLayout = QtGui.QVBoxLayout(content)
            		self.scrollbar = self.verticalScrollBar()
            
            	def addLine(self, widget1, widget2):
            
            		lineWidget = QtGui.QFrame()
            		lineWidget.setFrameStyle(QtGui.QFrame.StyledPanel)
            		lineLayout = QtGui.QHBoxLayout()
            		lineWidget.setLayout(lineLayout)
            		lineLayout.setAlignment(Qt.AlignLeft)
            		lineLayout.addWidget(widget1)
            		lineLayout.addWidget(widget2)
            		self.statusesLayout.addWidget(lineWidget)
            		widget2.setWordWrap(True)
            
            	def addStretch(self):
            
            		self.statusesLayout.addStretch()
            
            app = QtGui.QApplication(sys.argv)
            main = QtGui.QWidget()
            layout = QtGui.QHBoxLayout(main)
            main.show()
            testWidget = QtGui.QHBoxLayout()
            layout.addWidget(statusUI())
            sys.exit(app.exec_())
            

            It seems to start expanding just fine.
            Screenshot from 2021-08-04 13-22-32.png

            But when I get to the last 0.000, it starts to take a lot more space than it usually would when expanding...
            Screenshot from 2021-08-04 13-23-31.png

            And then it just cuts off the last 0.000 for some reason.
            Screenshot from 2021-08-04 13-23-46.png

            Can someone tell me why this is happening? Thanks for any help!
            I think I'm using PyQt5, although I have to import from pyqtgraph else it doesn't work for some reason.

            eyllanescE Offline
            eyllanescE Offline
            eyllanesc
            wrote on last edited by eyllanesc
            #4

            @Hexrin The problem is mainly caused by the line lineLayout.setAlignment(Qt.AlignLeft) that you probably used so that the first column occupies the minimum space but also makes the second column compress. Instead I use stretch factors.

            import sys
            
            from pyqtgraph import QtCore, QtGui
            
            
            class statusUI(QtGui.QPushButton):
                def __init__(self):
                    QtGui.QPushButton.__init__(self)
                    self.setMinimumHeight(200)
                    statusUILayout = QtGui.QHBoxLayout(self)
                    self.scrollArea = dataScrollArea()
                    statusUILayout.addWidget(self.scrollArea)
            
                    self.setUpMagUI()
            
                def setUpMagUI(self):
                    text = str(
                        [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
                    ).translate({None: "'"})
            
                    self.magneticFieldCovNameLabel = QtGui.QLabel("Magnetic Field Covariance: ")
                    self.magneticFieldCovNumberLabel = QtGui.QLabel(text)
            
                    self.magneticFieldCovNameLabel.setAlignment(QtCore.Qt.AlignLeft)
                    self.magneticFieldCovNumberLabel.setAlignment(QtCore.Qt.AlignLeft)
            
                    self.scrollArea.addLine(
                        self.magneticFieldCovNameLabel, self.magneticFieldCovNumberLabel
                    )
            
                    self.scrollArea.addStretch()
            
            
            class dataScrollArea(QtGui.QScrollArea):
                def __init__(self):
                    QtGui.QScrollArea.__init__(self)
                    self.setWidgetResizable(True)
                    content = QtGui.QWidget()
                    self.setWidget(content)
                    self.statusesLayout = QtGui.QVBoxLayout(content)
            
                def addLine(self, widget1, widget2):
                    widget2.setWordWrap(True)
                    lineWidget = QtGui.QFrame()
                    lineLayout = QtGui.QHBoxLayout(lineWidget)
                    lineWidget.setLayout(lineLayout)
                    lineLayout.addWidget(widget1)
                    lineLayout.addWidget(widget2, stretch=1)
                    self.statusesLayout.addWidget(lineWidget)
            
                def addStretch(self):
                    self.statusesLayout.addStretch()
            
            app = QtGui.QApplication(sys.argv)
            main = QtGui.QWidget()
            main.resize(640, 480)
            layout = QtGui.QHBoxLayout(main)
            main.show()
            testWidget = QtGui.QHBoxLayout()
            layout.addWidget(statusUI())
            sys.exit(app.exec_())
            

            Output:

            Screenshot_20210804_160510.png

            Screenshot_20210804_160520.png

            Please for a next time remove unnecessary imports and also note that from pyqtgraph import QtCore, QtGui and from PyQt5 import QtCore, QtGui may conflict causing silent bugs.

            If you want me to help you develop some work then you can write to my email: e.yllanescucho@gmal.com.

            H 1 Reply Last reply
            2
            • eyllanescE eyllanesc

              @Hexrin The problem is mainly caused by the line lineLayout.setAlignment(Qt.AlignLeft) that you probably used so that the first column occupies the minimum space but also makes the second column compress. Instead I use stretch factors.

              import sys
              
              from pyqtgraph import QtCore, QtGui
              
              
              class statusUI(QtGui.QPushButton):
                  def __init__(self):
                      QtGui.QPushButton.__init__(self)
                      self.setMinimumHeight(200)
                      statusUILayout = QtGui.QHBoxLayout(self)
                      self.scrollArea = dataScrollArea()
                      statusUILayout.addWidget(self.scrollArea)
              
                      self.setUpMagUI()
              
                  def setUpMagUI(self):
                      text = str(
                          [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]
                      ).translate({None: "'"})
              
                      self.magneticFieldCovNameLabel = QtGui.QLabel("Magnetic Field Covariance: ")
                      self.magneticFieldCovNumberLabel = QtGui.QLabel(text)
              
                      self.magneticFieldCovNameLabel.setAlignment(QtCore.Qt.AlignLeft)
                      self.magneticFieldCovNumberLabel.setAlignment(QtCore.Qt.AlignLeft)
              
                      self.scrollArea.addLine(
                          self.magneticFieldCovNameLabel, self.magneticFieldCovNumberLabel
                      )
              
                      self.scrollArea.addStretch()
              
              
              class dataScrollArea(QtGui.QScrollArea):
                  def __init__(self):
                      QtGui.QScrollArea.__init__(self)
                      self.setWidgetResizable(True)
                      content = QtGui.QWidget()
                      self.setWidget(content)
                      self.statusesLayout = QtGui.QVBoxLayout(content)
              
                  def addLine(self, widget1, widget2):
                      widget2.setWordWrap(True)
                      lineWidget = QtGui.QFrame()
                      lineLayout = QtGui.QHBoxLayout(lineWidget)
                      lineWidget.setLayout(lineLayout)
                      lineLayout.addWidget(widget1)
                      lineLayout.addWidget(widget2, stretch=1)
                      self.statusesLayout.addWidget(lineWidget)
              
                  def addStretch(self):
                      self.statusesLayout.addStretch()
              
              app = QtGui.QApplication(sys.argv)
              main = QtGui.QWidget()
              main.resize(640, 480)
              layout = QtGui.QHBoxLayout(main)
              main.show()
              testWidget = QtGui.QHBoxLayout()
              layout.addWidget(statusUI())
              sys.exit(app.exec_())
              

              Output:

              Screenshot_20210804_160510.png

              Screenshot_20210804_160520.png

              Please for a next time remove unnecessary imports and also note that from pyqtgraph import QtCore, QtGui and from PyQt5 import QtCore, QtGui may conflict causing silent bugs.

              H Offline
              H Offline
              Hexrin
              wrote on last edited by
              #5

              @eyllanesc

              Thank you!

              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