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. QComboBox not aligned with QPushButton

QComboBox not aligned with QPushButton

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 1 Posters 319 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.
  • F Offline
    F Offline
    fvez_demtroys
    wrote on last edited by
    #1

    Hi,

    We are making an internal configuration tool using PyQt5 5.15.4.
    Development is done on macOS Catalina 10.15.7
    The final version will run on both OSX and Windows 10

    I am having an issue where my QComboBox isn't aligning properly with my QPushButtons.
    This issue is not present with a QLineEdit.

    Here is a sample script allowing to showcase both situations.

    import sys
    
    from PyQt5.QtWidgets import *
    from UI import Ui_mainWindow
    
    
    class App(QMainWindow):
    	def __init__(self):
    		super(App, self).__init__()
    		self.initUI()
    		self.show()
    
    	def initUI(self):
    		self.mainWindow = Ui_mainWindow()
    		self.mainWindow.setupUi(self)
    
    
    class Ui_mainWindow(QMainWindow):
    	def __init__(self):
    		super().__init__()
    
    	def setupUi(self, mainWindow):
    		if not mainWindow.objectName():
    			mainWindow.setObjectName(u"mainWindow")
    
    		self.centralWidget = QWidget(mainWindow)
    		self.centralWidget.setObjectName(u"centralWidget")
    		self.baseGridLayout = QGridLayout(self.centralWidget)
    		self.baseGridLayout.setObjectName(u"baseGridLayout")
    
    		self.groupBox = QGroupBox(self.centralWidget)
    		self.groupBox.setObjectName(u"groupBox")
    		self.groupBox.setFlat(True)
    		self.gridLayout = QGridLayout()
    		self.gridLayout.setObjectName(u'gridLayout')
    		self.gridLayout.setContentsMargins(10, 10, 10, 10)
    		self.gridLayout.setSpacing(0)
    
    		self.lineEdit = QLineEdit()
    		self.lineEdit.setObjectName(u"lineEdit")
    		self.lineEdit.setPlaceholderText('Placeholder Text')
    		self.gridLayout.addWidget(self.lineEdit, 0, 0, 1, 3)
    
    		self.pushButton_one = QPushButton()
    		self.pushButton_one.setObjectName(u"pushButton_one")
    		self.pushButton_one.setText('One')
    		self.gridLayout.addWidget(self.pushButton_one, 1, 0, 1, 1)
    
    		self.pushButton_two = QPushButton()
    		self.pushButton_two.setObjectName(u"pushButton_two")
    		self.pushButton_two.setText('Two')
    		self.gridLayout.addWidget(self.pushButton_two, 1, 2, 1, 1)
    
    		self.emptyLabel = QLabel()
    		self.emptyLabel.setObjectName(u"emptyLabel")
    		self.gridLayout.addWidget(self.emptyLabel, 2, 0, 1, 1)
    
    		self.comboBox = LabelAndComboBox(self.groupBox)
    		self.comboBox.setObjectName(u"comboBox")
    		self.gridLayout.addWidget(self.comboBox, 3, 0, 1, 3)
    
    		self.pushButton_three = QPushButton()
    		self.pushButton_three.setObjectName(u"pushButton_three")
    		self.pushButton_three.setText('Three')
    		self.gridLayout.addWidget(self.pushButton_three, 4, 0, 1, 1)
    
    		self.pushButton_four = QPushButton()
    		self.pushButton_four.setObjectName(u"pushButton_four")
    		self.pushButton_four.setText('Four')
    		self.gridLayout.addWidget(self.pushButton_four, 4, 2, 1, 1)
    
    		self.groupBox.setLayout(self.gridLayout)
    
    		self.setCentralWidget(self.centralWidget)
    
    		mainWindow.setCentralWidget(self.centralWidget)
    		self.baseGridLayout.addWidget(self.groupBox, 0, 0, 1, 1)
    
    
    class LabelAndComboBox(QWidget):
    	def __init__(self, parent=None):
    		super(QWidget, self).__init__(parent)
    		self.layout = QVBoxLayout(self)
    		self.layout.setContentsMargins(0, 0, 0, 0)
    
    		self.label = QLabel('Label Text')
    
    		self.comboBox = QComboBox()
    		self.comboBox.addItems(['item one', 'item two', 'item three'])
    
    		self.layout.addWidget(self.label)
    		self.layout.addWidget(self.comboBox)
    
    
    if __name__ == "__main__":
    	app = QApplication(sys.argv)
    	ex = App()
    	sys.exit(app.exec_())
    

    When you run the script, you can clearly see that the QLineEdit is aligned correctly with the QPushButton and that the QComboBox is not aligned correctly.
    Any idea why?

    Thanks in advance,
    FVez

    1 Reply Last reply
    0
    • F Offline
      F Offline
      fvez_demtroys
      wrote on last edited by
      #2

      Here are some images to help visualize the issue.

      1 Reply Last reply
      0
      • F Offline
        F Offline
        fvez_demtroys
        wrote on last edited by
        #3

        Does anyone know how to handle this?

        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