Solved Putting buttons and textboxes in specific positions
-
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) ?
-
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.
-
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... -
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.
-
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!
-
Nothing stands out for that in the code so I am guessing it comes from the Matplotlib part.
-
Yes, he has changed it. The the original code , without this change, is here https://github.com/kklmn/OrthoView/blob/master/OrthoView.py Thanks...
-
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...