Python Forum

Full Version: Python UI - Getting Label to show to left of QLineEdit
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I would like the QLineEdit field to follow the label.

Right now the label lives in the upper left hand corner of the dialogue box.



"""
Import block
"""
from PyQt4 import QtCore
from PyQt4 import QtGui

"""
Classes block
"""
class UI_central(QtGui.QDialog):

    def __init__(self, parent=None):
        super(UI_central, self).__init__(parent)
        
        label1 = QtGui.QLabel('Stock', self)
        
        self.line_edit = QtGui.QLineEdit()
        self.line_edit.setText("Starting...")
        
        hbox = QtGui.QHBoxLayout()
        hbox.addWidget(self.line_edit)
        self.setLayout(hbox)
        
        submit_button = QtGui.QPushButton("Submit")
        clear_button = QtGui.QPushButton("Clear")

        hbox.addWidget(submit_button)
        hbox.addWidget(clear_button)

        self.connect(submit_button, QtCore.SIGNAL("clicked()"),
                     self.submit)

        self.connect(clear_button, QtCore.SIGNAL("clicked()"),
                     self.clear)
        return
    
    def submit(self):
        str = self.line_edit.text()
        print(str)

    def clear(self):
        print ("cleared")
        self.line_edit.setText("")
Disregard.

Found a few mistakes within my code and got it to run successfully.

Thanks for viewing. Tongue