Answer the question
In order to leave comments, you need to log in
How to align a button in pyqt5?
I need to align the button to the bottom left. I tried to do this for the test:
self.verticalLayout.addWidget(button, alignment=QtCore.Qt.AlignRight)
But writes AttributeError: 'main' object has no attribute 'verticalLayout'
This is how I create the class: class main(QWidget):
Answer the question
In order to leave comments, you need to log in
In order to use the self.verticalLayout attribute, you must first assign it the value of a Layout object from PyQt.
self.name is an attribute of your class, only instead of name, verticalLayout.
from PyQt5 import QtWidgets, QtCore
class WindowLayout(object):
def __init__(self):
button = QtWidgets.QWidget
self.verticalLayout = QtWidgets.QVBoxLayout(parent)
self.verticalLayout.addWidget(button, alignment=QtCore.Qt.AlignRight)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question