Python Forum
Python UI - Getting Label to show to left of QLineEdit
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Python UI - Getting Label to show to left of QLineEdit
#1
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("")
Reply
#2
Disregard.

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

Thanks for viewing. Tongue
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Evaluating math from left to right in coding hannahlynn 3 2,414 Mar-23-2021, 09:31 PM
Last Post: deanhystad
  Python code unable to show Bokeh line chart kirito85 2 2,467 Feb-06-2019, 07:52 AM
Last Post: kirito85
  Setup a label by binding listbox importing a subclass method using python 3 and tkint Dannds 0 2,749 Mar-21-2017, 09:38 PM
Last Post: Dannds

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020