ChatCrawlersearch across public Telegram Open the app
Q

Qt for Python (PySide/Shiboken)

30 August 2022
2022-08-30×
30 August 2022
В
Hello! Sorry for being a little offtopic. I am a Python junior developer. I am using PyQt5.QtWidgets Python module. My problem is with laying out widgets on parent object, so I guess they are not Python-specific. Namely, I need a widget to be positioned using GridLayout, and then I need to delete it a little later. If I create a widget specifying a parent widget among constructor arguments, ia gets automatically positioned on a parent widget, which is what I don't want. If I do not specify parent explicitly, but instead create a QGridLaoyut object in a parent widget and add my child widget using AddWidget method of a QGridLaoyut object, widget is positioned OK, but I cannot reach it from a parent (because this is not its parent, as mentioned earlier). So the questions are: 1. How can I maintain some control ovet my child widgets without getting them auto-positioned by the parent? 2. How exactly are child widgets positioned on a parent (if parent is specified)? I checked parent layout() method, and it does not return any valid laoyut object. Thanks in advance!
it does not matter if they have a parent or not *if* they are inside of a layout.
now, if you *dont* want the layout to automatically position them, you can call setGeometry on them. that's really not nice. :)
T
specially because you have no idea if something will be painted above or below it, when you use setGeometry.
В
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?
F
I don't understand - if you don't want your widgets to be positioned automatically, why use a layout? That's kind of its job?
T
please show us your code, there something quite wrong on it.
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 uncomment creation of a grid layout, even without addWidget calls one of the button is seen a little taller than without grid layout creation, and its pressbutton method is called. Right now pressbutton methods are not called.
T
self.grid.addWidget(self.btn1, ... )
В
My problem is most likely solved anyway, thanks a lot.
Calendar: August 2022
MoTuWeThFrSaSu1223445406786941029111812131415161718191201212212322243251262732829193025313
Archive by month
Open in Telegram Каталог площадок Искать в ChatCrawler

A snapshot of an open public feed from the search index ChatCrawler — “Google for public Telegram”; refreshed as the venue is crawled. Times are UTC.

Public content only, official Telegram API. About · FAQ · What we do not do · Remove a page · Catalog