Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Putting buttons and textboxes in specific positions
Forum Updated to NodeBB v4.3 + New Features

Putting buttons and textboxes in specific positions

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 1.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.
  • J Offline
    J Offline
    john_hobbyist
    wrote on last edited by john_hobbyist
    #8

    Ok, this is the code of the textbox, that I want to put under the image viewer box:

     . . .
    self.textEdit = QTextEdit()
    self.textEdit.setReadOnly(True)
    . . . 
    mylayout = qtWidgets.QHBoxLayout()
    mylayout.addWidget(self.textEdit)
     . . .
    # somewhere down to the the code I print the messages that work ok.
    

    As it is now, it prints the text box next to (on the right of) the image viewer box. Any idea how to put it under the image viewer?

    1 Reply Last reply
    0
    • Christian EhrlicherC Offline
      Christian EhrlicherC Offline
      Christian Ehrlicher
      Lifetime Qt Champion
      wrote on last edited by Christian Ehrlicher
      #9

      @john_hobbyist said in Putting buttons and textboxes in specific positions:

      Any idea how to put it under the image viewer?

      Really?

      mylayout = qtWidgets.QHBoxLayout()

      Can it be more obvious? Use a proper layout...

      Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
      Visit the Qt Academy at https://academy.qt.io/catalog

      J 1 Reply Last reply
      1
      • Christian EhrlicherC Christian Ehrlicher

        @john_hobbyist said in Putting buttons and textboxes in specific positions:

        Any idea how to put it under the image viewer?

        Really?

        mylayout = qtWidgets.QHBoxLayout()

        Can it be more obvious? Use a proper layout...

        J Offline
        J Offline
        john_hobbyist
        wrote on last edited by john_hobbyist
        #10

        @Christian-Ehrlicher Ok, I changed it to mylayout = qtWidgets.QVBoxLayout() and now all the things that were one next to the other went in Vertical. What were horizontal form left to right: 1) image viewer, 2)text boxt, 3)directory box, 3)button. I am trying however to put only the text box and the button under image viewer and on the right of the image viewer the directory box... (I am using PyQt about a month, and I am trying to learn... I am trying many hours a day..)Thanks!

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

          Please take the time to read the Qt's documentation chapter about layouts.

          You can use several and assemble them to reach your goal.

          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
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #12

            Then take a look at the layout documentation and find out what other layouts are possible.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            1 Reply Last reply
            2
            • J Offline
              J Offline
              john_hobbyist
              wrote on last edited by
              #13

              @SGaist @Christian-Ehrlicher : Ok, I will study it, thanx a lot for your time!

              1 Reply Last reply
              0
              • J Offline
                J Offline
                john_hobbyist
                wrote on last edited by john_hobbyist
                #14

                I am studying the link you posted today... I have done some progress eventually! I use GridLayout class. So I have an object on row = 0, column = 0 , an object on r = 0, c = 1, and an object on r = 0, c=2. I am trying to put exactly 3 buttons under the first object, the one next to the other. I mean the 3 buttons to share the row = 1 and col = 0

                This is the code:

                layout.addWidget(self.button1, 1, 0)
                layout.addWidget(self.button2, 1, 1)
                layout.addWidget(self.button3, 1, 2)
                

                This does not work, it puts the buttons on the same row but on different columns. I even tried addItem() but it prints an error... Any ideas?

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

                  Out them in a horizontal layout and that layout in your grid layout.

                  As already said, you can combine layouts as explained in the linked documentation as well.

                  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
                  2
                  • J Offline
                    J Offline
                    john_hobbyist
                    wrote on last edited by john_hobbyist
                    #16

                    I did it but It does not run, I have been trying to fix this error for hours...

                    TypeError: arguments did not match any overloaded call:
                      addWidget(self, QWidget): argument 1 has unexpected type 'QHBoxLayout'
                      addWidget(self, QWidget, int, int, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = Qt.Alignment()): argument 1 has unexpected type 'QHBoxLayout'
                      addWidget(self, QWidget, int, int, int, int, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = Qt.Alignment()): argument 1 has unexpected type 'QHBoxLayout'
                    

                    Thanks...

                    jsulmJ 1 Reply Last reply
                    0
                    • J john_hobbyist

                      I did it but It does not run, I have been trying to fix this error for hours...

                      TypeError: arguments did not match any overloaded call:
                        addWidget(self, QWidget): argument 1 has unexpected type 'QHBoxLayout'
                        addWidget(self, QWidget, int, int, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = Qt.Alignment()): argument 1 has unexpected type 'QHBoxLayout'
                        addWidget(self, QWidget, int, int, int, int, alignment: Union[Qt.Alignment, Qt.AlignmentFlag] = Qt.Alignment()): argument 1 has unexpected type 'QHBoxLayout'
                      

                      Thanks...

                      jsulmJ Offline
                      jsulmJ Offline
                      jsulm
                      Lifetime Qt Champion
                      wrote on last edited by
                      #17

                      @john_hobbyist You have to use addLayout(), not addWidget() if you want to add a layout to another one, all explained in documentation...

                      https://forum.qt.io/topic/113070/qt-code-of-conduct

                      1 Reply Last reply
                      4

                      • Login

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