Python Forum
Python UI - Getting Label to show to left of QLineEdit - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Homework (https://python-forum.io/forum-9.html)
+--- Thread: Python UI - Getting Label to show to left of QLineEdit (/thread-6210.html)



Python UI - Getting Label to show to left of QLineEdit - ijosefson - Nov-10-2017

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("")



RE: Python UI - Getting Label to show to left of QLineEdit - ijosefson - Nov-11-2017

Disregard.

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

Thanks for viewing. Tongue