The label is given a fixed width via label.setFixedWidth(200)
.
The text inside of label is shorter then label's width. As it is now the label text is being centered within a label. But I would like the text to be aligned with the label's right side so the text right side is edge by edge to lineEdit widget left edge.
from PyQt4 import QtCore, QtGui
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.resize(720, 480)
cWidget = QtGui.QWidget(self)
self.setCentralWidget(cWidget)
layout = QtGui.QHBoxLayout(cWidget)
label = QtGui.QLabel(" Label Text Value: ")
label.setFixedWidth(200)
layout.addWidget(label)
textEdit = QtGui.QTextEdit()
textEdit.setMaximumHeight(14)
layout.addWidget(textEdit)
button=QtGui.QPushButton("Browse")
layout.addWidget(button)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
frame = MainWindow()
frame.show()
sys.exit(app.exec_())
If you don't want to use spacers, this does this trick:
label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With