Important: Please read the Qt Code of Conduct -

Move label in QVBoxLayout()

  • Hello everyone, i am adding widgets (labels) to QVBoxLayout() is any way to organise them inside QVBoxLayout()? Move to position i need. When i try to use move or resize it is not working.

  • Lifetime Qt Champion


    If you want to reorder them your can use replaceWidget and then insertItem with the item returned by replaceWidget. Or takeAt.

  • @Samuel-Bachorik
    Not sure whether you mean what @SGaist has answered --- i.e. you are talking about inserting & removing the labels within the QVBoxLayout --- or whether you are talking about actually moving labels to a particular position, which you should be doing via adding sub-layouts/stretches/alignment etc.?

  • I am talking about moving my labels to exact position.

    As you can see here, these labels are wide as my QVBoxLayout() or Qwidget. How can i make these labels smaller?
    Also how can i move this labels from left side of window. I dont understand how this is wokring. Simply i add label and i can not do anything with it ? Iam leaving also code.


    from PyQt5.QtCore import Qt, QSize
    from PyQt5 import QtWidgets, uic
    import sys
    from PyQt5.QtGui import QIcon, QPixmap
    from PyQt5.QtWidgets import *
    from PyQt5.QtGui import *
    import sys
    class MainWindow(QMainWindow):
        def __init__(self):
            self.setGeometry(200, 250, 900, 600)
            self.scroll = QScrollArea()
            self.widget = QWidget()
            self.vbox = QVBoxLayout()
            self.namer2 = ["a","b","c","d","e","b","c","d","e","b","c","d","e"]
            self.counter2 = 0
            for i in range(50):
                self.namer2[self.counter2] = QLabel("Hello  \nall\nguys")  # AS YOU CAN SEE HERE IAM ADDING LABEL BUT HOW TO MOVE AND MAKE IT SMALLER ? 
                self.namer2[self.counter2].setStyleSheet("background-color: lightgreen")
                self.namer2[self.counter2].resize(20, 50)
                self.namer2[self.counter2].setFont(QFont('Arial', 12))
            #Scroll Area Properties
    def main():
        app = QtWidgets.QApplication(sys.argv)
        main = MainWindow()
    if __name__ == '__main__':

  • Lifetime Qt Champion

    You can set their maximum size.

    What exactly are you after ?

  • Iam sorry i think iam not using right tools to achieve what i need.

  • Lifetime Qt Champion

    @Samuel-Bachorik said in Move label in QVBoxLayout():

    Iam sorry i think iam not using right tools to achieve what i need.

    Maybe, maybe not. If you explain what you are trying to achieve, then we might be able to assist a bit more.

  • @SGaist I am trying to make something like chat app. I made this in photoshop just o show how i want this to looks like. Labels like this. Of course text on them. And scroll down and up. These labels should be messages. I just can not fit something like this in QScrollArea().


  • Lifetime Qt Champion

    In that case you should rather use a QListView and a custom QStyledItemDelegate.

  • Thank you i will try tomorrow soon as possible.

Log in to reply