Pop-up with colors and data
-
@JonB Ι re-post:
As I checked from here: https://doc.qt.io/qt-5/layout.html under paragraph: "Qt's Layout Classes":
I use these classes:
QHBoxLayout
and
QSizePolicy
under this method (and after that is the method I described previously):
class Thing(QMainWindow): def __init__(self, parent = None): . . . (here are the QHBoxLayout and QSizePolicy used) . . . def PrintGridLayout (self): win = QWidget() grid=QGridLayout() grid.addWidget(QLabel("Yellow"), 1,1) grid.addWidget(QPushButton("B"+str(1)+str(2)),1,2) grid.addWidget(QLabel("Red"), 2,1) grid.addWidget(QPushButton("B"+str(2)+str(2)),2,2) grid.addWidget(QLabel("Blue"), 3,1) grid.addWidget(QPushButton("B"+str(3)+str(2)),3,2) win.setLayout(grid) win.setGeometry(100,100,200,100) win.setWindowTitle("PyQt") win.show()
So how do I delete the existing layout manager? And especially since they are on a different class??
@john_hobbyist
If you do not get an error message you have nothing to do. If you do get an error message then show it, and find the line which caused in it which I think Python will show in the message. This is the third time I have said this. -
@john_hobbyist
If you do not get an error message you have nothing to do. If you do get an error message then show it, and find the line which caused in it which I think Python will show in the message. This is the third time I have said this.@JonB No error, the method above runs (I checked it with print commands among the code). However, no GUI is displayed with the GridLayout, Buttons e.t.c.
-
@JonB No error, the method above runs (I checked it with print commands among the code). However, no GUI is displayed with the GridLayout, Buttons e.t.c.
@john_hobbyist said in Pop-up with colors and data:
However, no GUI is displayed with the GridLayout, Buttons e.t.c.
Could you please tell me: does this mean that an "empty" widget/window is displayed (presumably with title bar
PyQt
) or does this mean no widget/window at all is shown? -
@john_hobbyist said in Pop-up with colors and data:
However, no GUI is displayed with the GridLayout, Buttons e.t.c.
Could you please tell me: does this mean that an "empty" widget/window is displayed (presumably with title bar
PyQt
) or does this mean no widget/window at all is shown?@JonB no widget/window at all is shown for this specific method...
-
@JonB no widget/window at all is shown for this specific method...
@john_hobbyist
So two possibilities occur to me:-
You create a widget (
win = QWidget()
) but never "attach" it anywhere to your main window. Where do you add it to that? -
Your
win = QWidget()
is a local reference which goes out of scope at the end ofPrintGridLayout
in Python, doesn't it? So won't it get destroyed, and hence no widget is shown?
So far as I can tell from what you are saying, you might as well remove all your
QGridLayout
code and you would see the same thing. So it has nothing to do with using the layout, it just isn't showing the widget? -
-
@john_hobbyist
So two possibilities occur to me:-
You create a widget (
win = QWidget()
) but never "attach" it anywhere to your main window. Where do you add it to that? -
Your
win = QWidget()
is a local reference which goes out of scope at the end ofPrintGridLayout
in Python, doesn't it? So won't it get destroyed, and hence no widget is shown?
So far as I can tell from what you are saying, you might as well remove all your
QGridLayout
code and you would see the same thing. So it has nothing to do with using the layout, it just isn't showing the widget?@JonB said in Pop-up with colors and data:
@john_hobbyist
So two possibilities occur to me:-
You create a widget (
win = QWidget()
) but never "attach" it anywhere to your main window. Where do you add it to that? -
Your
win = QWidget()
is a local reference which goes out of scope at the end ofPrintGridLayout
in Python, doesn't it? So won't it get destroyed, and hence no widget is shown? -
So far as I can tell from what you are saying, you might as well remove all your
QGridLayout
code and you would see the same thing. So it has nothing to do with using the layout, it just isn't showing the widget?
-
Nowhere
-
I am not sure...I think yes
-
Yes, either I have the method or I do not have it, it is the same thing...nothing displayed...
-
-
@JonB said in Pop-up with colors and data:
@john_hobbyist
So two possibilities occur to me:-
You create a widget (
win = QWidget()
) but never "attach" it anywhere to your main window. Where do you add it to that? -
Your
win = QWidget()
is a local reference which goes out of scope at the end ofPrintGridLayout
in Python, doesn't it? So won't it get destroyed, and hence no widget is shown? -
So far as I can tell from what you are saying, you might as well remove all your
QGridLayout
code and you would see the same thing. So it has nothing to do with using the layout, it just isn't showing the widget?
-
Nowhere
-
I am not sure...I think yes
-
Yes, either I have the method or I do not have it, it is the same thing...nothing displayed...
@john_hobbyist said in Pop-up with colors and data:
Yes, either I have the method or I do not have it, it is the same thing...nothing displayed...
So you should start by mentioning that! :)
Can we take a step back. What are you trying to do? You have a
QMainWindow
. That comes with its own layout, all described in Qt Main Window Framework. Are you just wanting to set its central widget to this grid?If per your title it's supposed to be a "popup" window, you'd have to look up "popup", or use a modeless dialog, I'm not sure about that bit.
For now, try changing your
win = QWidget()
to
self.win = QWidget(self)
and obviously those mentions of
win...
toself.win...
. Better? -
-
@john_hobbyist said in Pop-up with colors and data:
Yes, either I have the method or I do not have it, it is the same thing...nothing displayed...
So you should start by mentioning that! :)
Can we take a step back. What are you trying to do? You have a
QMainWindow
. That comes with its own layout, all described in Qt Main Window Framework. Are you just wanting to set its central widget to this grid?If per your title it's supposed to be a "popup" window, you'd have to look up "popup", or use a modeless dialog, I'm not sure about that bit.
For now, try changing your
win = QWidget()
to
self.win = QWidget(self)
and obviously those mentions of
win...
toself.win...
. Better?@JonB said in Pop-up with colors and data:
@john_hobbyist said in Pop-up with colors and data:
Yes, either I have the method or I do not have it, it is the same thing...nothing displayed...
So you should start by mentioning that! :)
Can we take a step back. What are you trying to do? You have a
QMainWindow
. That comes with its own layout, all described in Qt Main Window Framework. Are you just wanting to set its central widget to this grid?If per your title it's supposed to be a "popup" window, you'd have to look up "popup", or use a modeless dialog, I'm not sure about that bit.
For now, try changing your
win = QWidget()
to
self.win = QWidget(self)
and obviously those mentions of
win...
toself.win...
. Better?I have a QMainWindow that opens, everything ok. It has menus where you choose what you want to see. In one of these menus I have a choice, where, when you choose it a new window should pop-up and show colored boxes and buttons...
Yes, I tried it with self.win = QWidget(self) nothing changed, again nothing was displayed....
-
@JonB said in Pop-up with colors and data:
@john_hobbyist said in Pop-up with colors and data:
Yes, either I have the method or I do not have it, it is the same thing...nothing displayed...
So you should start by mentioning that! :)
Can we take a step back. What are you trying to do? You have a
QMainWindow
. That comes with its own layout, all described in Qt Main Window Framework. Are you just wanting to set its central widget to this grid?If per your title it's supposed to be a "popup" window, you'd have to look up "popup", or use a modeless dialog, I'm not sure about that bit.
For now, try changing your
win = QWidget()
to
self.win = QWidget(self)
and obviously those mentions of
win...
toself.win...
. Better?I have a QMainWindow that opens, everything ok. It has menus where you choose what you want to see. In one of these menus I have a choice, where, when you choose it a new window should pop-up and show colored boxes and buttons...
Yes, I tried it with self.win = QWidget(self) nothing changed, again nothing was displayed....
@john_hobbyist
Then I give up. You do callPrintGridLayout()
, don't you, and you have checked it is being executed...? -
@john_hobbyist
Then I give up. You do callPrintGridLayout()
, don't you, and you have checked it is being executed...?@JonB said in Pop-up with colors and data:
@john_hobbyist
Then I give up. You do callPrintGridLayout()
, don't you, and you have checked it is being executed...?Yes I call it from main program like that:
test = QAction("Testing Layout", self) file.addAction(test) # here test.triggered.connect(self.PrintGridLayout)
Yes the code runs, but the window is not displayed....
Thanks for your try and your time though... :-)
-
It needed:
self.setLayout(grid)
Thanks for you time! I mark it as solved!
-
It needed:
self.setLayout(grid)
Thanks for you time! I mark it as solved!
@john_hobbyist
If you decided you wantedself.setLayout(grid)
--- insidePrintGridLayout ()
soself
isThing(QMainWindow)
right? --- could you explain to me what you wanted the wholewin = QWidget()
for??Not to mention that if
self
is aQMainWindow
and you goself.setLayout()
you should be back to getting the "which already has a layout" warning?