Solved Putting buttons and textboxes in specific positions
-
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?
-
@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...
-
@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!
-
Please take the time to read the Qt's documentation chapter about layouts.
You can use several and assemble them to reach your goal.
-
Then take a look at the layout documentation and find out what other layouts are possible.
-
@SGaist @Christian-Ehrlicher : Ok, I will study it, thanx a lot for your time!
-
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?
-
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.
-
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...
-
@john_hobbyist You have to use addLayout(), not addWidget() if you want to add a layout to another one, all explained in documentation...