Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Move label in QVBoxLayout()

Move label in QVBoxLayout()

Scheduled Pinned Locked Moved Unsolved Qt for Python
10 Posts 3 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Samuel Bachorik
    wrote on last edited by
    #1

    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.

    JonBJ 1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

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

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      1
      • S Samuel Bachorik

        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.

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by
        #3

        @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.?

        1 Reply Last reply
        1
        • S Offline
          S Offline
          Samuel Bachorik
          wrote on last edited by Samuel Bachorik
          #4

          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.

          2818c5ed-43ef-4096-a0d3-586a159c2411-image.png

          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):
                  super().__init__()
                  self.setGeometry(200, 250, 900, 600)
                  self.setWindowTitle("Hello")
          
                  self.scroll = QScrollArea()
                  self.scroll.setFixedWidth(350)
                  self.scroll.setFixedHeight(500)
                  self.widget = QWidget()
                  self.widget.setFixedWidth(350)
          
                  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))
          
                      self.vbox.addWidget(self.namer2[self.counter2])
                      self.vbox.addSpacing(65)
          
          
                  self.widget.setLayout(self.vbox)
          
                  #Scroll Area Properties
                  self.scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
                  self.scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
                  self.scroll.setWidgetResizable(True)
                  self.scroll.setWidget(self.widget)
          
          
          
                  self.setCentralWidget(self.scroll)
          
          
                  self.show()
          
          
          
          def main():
              app = QtWidgets.QApplication(sys.argv)
              main = MainWindow()
              sys.exit(app.exec_())
          
          if __name__ == '__main__':
              main()
          
          1 Reply Last reply
          0
          • SGaistS Offline
            SGaistS Offline
            SGaist
            Lifetime Qt Champion
            wrote on last edited by
            #5

            You can set their maximum size.

            What exactly are you after ?

            Interested in AI ? www.idiap.ch
            Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

            1 Reply Last reply
            1
            • S Offline
              S Offline
              Samuel Bachorik
              wrote on last edited by
              #6

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

              SGaistS 1 Reply Last reply
              0
              • S Samuel Bachorik

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

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @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.

                Interested in AI ? www.idiap.ch
                Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                1 Reply Last reply
                1
                • S Offline
                  S Offline
                  Samuel Bachorik
                  wrote on last edited by Samuel Bachorik
                  #8

                  @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().

                  b8bb92bf-0594-4d4f-8602-03e3faf97788-image.png

                  1 Reply Last reply
                  0
                  • SGaistS Offline
                    SGaistS Offline
                    SGaist
                    Lifetime Qt Champion
                    wrote on last edited by SGaist
                    #9

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

                    Interested in AI ? www.idiap.ch
                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                    1 Reply Last reply
                    3
                    • S Offline
                      S Offline
                      Samuel Bachorik
                      wrote on last edited by
                      #10

                      Thank you i will try tomorrow soon as possible.

                      1 Reply Last reply
                      0

                      • Login

                      • Login or register to search.
                      • First post
                        Last post
                      0
                      • Categories
                      • Recent
                      • Tags
                      • Popular
                      • Users
                      • Groups
                      • Search
                      • Get Qt Extensions
                      • Unsolved