30 August 2022
Всеволод Никоноров2. maybe my question is not clear. Widgets in fact are positioned on a parent even if I did not call any layout methods explicitly. If a widget is positioned, there should be a layout object controlling it, shouldn't it?
if you just specify a parent, they are not automatically added to a layout
Всеволод НиконоровIs there a way to iterate over a layout's children?
there is.
a layout children is *not* a widget, but a LayoutItem, that contains a widget.
please look at the documentation for that.
tomaz canabravaif you just specify a parent, they are not automatically added to a layout
But I sure see them right after creation. Overlapping one another.
FreyaI don't understand - if you don't want your widgets to be positioned automatically, why use a layout? That's kind of its job?
I want them not just partitioned in any way, but in one specific way - using GridLayout
Всеволод НиконоровBut I sure see them right after creation. Overlapping one another.
then create then and imediately add them to the grid layout.
tomaz canabravathere is.
a layout children is *not* a widget, but a LayoutItem, that contains a widget.
please look at the documentation for that.
Thanks for the hint. This way I can call their methods!
tomaz canabravathen create then and imediately add them to the grid layout.
If I add widgets they appear on a window immediately, but are in fact not laid out. Interesting thing: QPushButton.clicked.connect() does not work before laying out a button, even though button visually respond when I try to click it.
Всеволод НиконоровIf I add widgets they appear on a window immediately, but are in fact not laid out. Interesting thing: QPushButton.clicked.connect() does not work before laying out a button, even though button visually respond when I try to click it.
No, that's incorrect.
The dialogs are visible *if* the eventloop has time to paint them, when you are on a method (or on the widget constructor), there's no way that a paint can run.
tomaz canabravaplease show us your code, there something quite wrong on it.
from PyQt5.QtWidgets import QApplication, QWidget, QPushButton, QGridLayout
import sys
class View(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
self.btn1 = QPushButton(self, text="very long button name")
self.btn2 = QPushButton(self, text="short name")
self.btn1.clicked.connect(self.pressbutton1)
self.btn2.clicked.connect(self.pressbutton2)
#self.grid = QGridLayout()
#self.setLayout(self.grid)
def pressbutton1(self):
print(1, flush=True)
def pressbutton2(self):
print(2, flush=True)
def main():
app = QApplication([])
view = View()
view.show()
sys.exit(app.exec())
if name == "__main__":
main()
Всеволод НиконоровIf I add widgets they appear on a window immediately, but are in fact not laid out. Interesting thing: QPushButton.clicked.connect() does not work before laying out a button, even though button visually respond when I try to click it.
Here I mentioned the fact that click handler is not executed if button is not laid out.
31 August 2022
Cyber MechanicLooking for PySide/PyQT trainers
Ссылка
click to show
click to show
Like, company trainings? On-site (where?) or remote? I do this kind of thing: https://bruhin.software