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 Update on Monday, May 27th 2025

Putting buttons and textboxes in specific positions

Scheduled Pinned Locked Moved Solved General and Desktop
17 Posts 4 Posters 1.1k Views
  • 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
    #1

    Hello, I am using this code: https://github.com/Axel-Erfurt/OrthoViewLite . I have built textboxes and buttons, which now are placed randomly inside the application. How can I place them under the the place that the image is displayed? Moreover how do I format the textbox to a certain size (5 lines x 40 columns) ?

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

      Hi,

      Your description is a bit vague.

      Looks like you need layouts and possibly a tool bar but not knowing what you want to do exactly does not allow for better answers.

      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
        #3

        Ok I am searching it... In this link, there is an image: https://github.com/Axel-Erfurt/OrthoViewLite
        If I found example code of how to include a simple 5 lines x 40 columns QTextEdit box under the image and 2-3 QPushButtons under the image, I can configure it with my code. Thanks for your time...

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

          The image and tree view are put in a QHBoxLayout instance.

          If you want your additional widgets to go under them then use a QVBoxLayout.

          As for fixing the size of a QTextEdit, it's a bit more tricky as it will depend on the font used.

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

            Ok, I am searching at it. Thanks! If I can ask, in which lines of the code does this guy program the x,y coordinates that are printed up on the center of the PyQT application, when I move the mouse over the loaded image? Thank you again!

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

              Nothing stands out for that in the code so I am guessing it comes from the Matplotlib part.

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

              J 1 Reply Last reply
              1
              • SGaistS SGaist

                Nothing stands out for that in the code so I am guessing it comes from the Matplotlib part.

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

                Yes, he has changed it. The the original code , without this change, is here https://github.com/kklmn/OrthoView/blob/master/OrthoView.py Thanks...

                1 Reply Last reply
                0
                • 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