Pop-up with colors and data
-
I made the above code a method and I call it from PyQt5 GUI. The result is this:
QWidget::setLayout: Attempting to set QLayout "" on TestCode"", which already has a layout QCoreApplication::exec: The event loop is already running Segmentation fault (core dumped)
Any ideas what is wrong?
The method is this:
def PrintGridLayout (self): ....
-
I made the above code a method and I call it from PyQt5 GUI. The result is this:
QWidget::setLayout: Attempting to set QLayout "" on TestCode"", which already has a layout QCoreApplication::exec: The event loop is already running Segmentation fault (core dumped)
Any ideas what is wrong?
The method is this:
def PrintGridLayout (self): ....
@john_hobbyist said in Pop-up with colors and data:
def PrintGridLayout (self):
....Why don't you post whole code instead of ...?
-
@john_hobbyist said in Pop-up with colors and data:
def PrintGridLayout (self):
def PrintGridLayout (self): def PrintGridLayout (self): app = QApplication(sys.argv) 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() sys.exit(app.exec_())
-
@john_hobbyist said in Pop-up with colors and data:
def PrintGridLayout (self):
def PrintGridLayout (self): def PrintGridLayout (self): app = QApplication(sys.argv) 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() sys.exit(app.exec_())
@john_hobbyist said in Pop-up with colors and data:
def PrintGridLayout (self):
def PrintGridLayout (self):Why do you have nested PrintGridLayout?
Why do you have "app = QApplication(sys.argv)" and "sys.exit(app.exec_())"? As one of the error messages tells you you already have event loop running!Regarding first error: please read https://doc.qt.io/qt-5/qwidget.html#setLayout
-
@john_hobbyist said in Pop-up with colors and data:
def PrintGridLayout (self):
def PrintGridLayout (self):Why do you have nested PrintGridLayout?
Why do you have "app = QApplication(sys.argv)" and "sys.exit(app.exec_())"? As one of the error messages tells you you already have event loop running!Regarding first error: please read https://doc.qt.io/qt-5/qwidget.html#setLayout
@jsulm Yes the first one is a copy paste error from Kubuntu to here...
-
@jsulm said in Pop-up with colors and data:
app = QApplication(sys.argv)" and "sys.exit(app.exec_())
Thanks....I deleted these:
app = QApplication(sys.argv)
and
sys.exit(app.exec_())
and now I get only this error:
QWidget::setLayout: Attempting to set QLayout "" on TestCode"", which already has a layout
which I try to figure out how to solve it... because it shows only this error and nothing else is depicted in the PyQt5 GUI...
By the way, the above method I call it like this:
test = QAction("Testing Layout", self) file.addAction(test) # here test.triggered.connect(self.PrintGridLayout)
Update 1: However, the rest QAction choices (buttons) work well..
Update 2: I put everywhere inside the method code print commands... everything runs inside the method however nothing is displayed in the GUI...
-
@jsulm said in Pop-up with colors and data:
app = QApplication(sys.argv)" and "sys.exit(app.exec_())
Thanks....I deleted these:
app = QApplication(sys.argv)
and
sys.exit(app.exec_())
and now I get only this error:
QWidget::setLayout: Attempting to set QLayout "" on TestCode"", which already has a layout
which I try to figure out how to solve it... because it shows only this error and nothing else is depicted in the PyQt5 GUI...
By the way, the above method I call it like this:
test = QAction("Testing Layout", self) file.addAction(test) # here test.triggered.connect(self.PrintGridLayout)
Update 1: However, the rest QAction choices (buttons) work well..
Update 2: I put everywhere inside the method code print commands... everything runs inside the method however nothing is displayed in the GUI...
@john_hobbyist said in Pop-up with colors and data:
which I try to figure out how to solve it
That's why I suggested to read https://doc.qt.io/qt-5/qwidget.html#setLayout
Especially this part:
"If there already is a layout manager installed on this widget, QWidget won't let you install another. You must first delete the existing layout manager (returned by layout()) before you can call setLayout() with the new layout." -
@jsulm said in Pop-up with colors and data:
If there already is a layout manager installed on this widget
When to code runs, it opens a main window/GUI, and when the user chooses from the menu (QAction) , he can open an auxiliary window with some information. What should I delete? Both of them are required...
Can you give me an example code, in order to understand?
-
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): 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??
-
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): 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??
win = QWidget() ... win.setLayout(grid)
I would not expect this code to generate
QWidget::setLayout: Attempting to set QLayout "" on TestCode"", which already has a layout
since a blank
QWidget
does not already have a layout. OTOH, I would expectmainWindow.setLayout()
to do so, becauseQMainWindow
does start with a layout. So where exactly are you getting the error from? (I believe Python reports the source code line number in its full message?)When you copy & paste your code here, could you please take the time to do so correctly, as incorrect code pasting wastes peoples' time trying to understand. I very much doubt your code actually has
def PrintGridLayout (self): def PrintGridLayout (self):
as you show.
-
win = QWidget() ... win.setLayout(grid)
I would not expect this code to generate
QWidget::setLayout: Attempting to set QLayout "" on TestCode"", which already has a layout
since a blank
QWidget
does not already have a layout. OTOH, I would expectmainWindow.setLayout()
to do so, becauseQMainWindow
does start with a layout. So where exactly are you getting the error from? (I believe Python reports the source code line number in its full message?)When you copy & paste your code here, could you please take the time to do so correctly, as incorrect code pasting wastes peoples' time trying to understand. I very much doubt your code actually has
def PrintGridLayout (self): def PrintGridLayout (self):
as you show.
@JonB Ok, no problem with this message. The code worked for many days...! Ok, I will try to be more careful with copying.. My concern now is how do I delete the existing layout manager?
-
@JonB Ok, no problem with this message. The code worked for many days...! Ok, I will try to be more careful with copying.. My concern now is how do I delete the existing layout manager?
@john_hobbyist said in Pop-up with colors and data:
My concern now is how do I delete the existing layout manager?
Why do you want to delete if you do not get an error message? If you do get an error message, I asked you where it came from? I am totally uncertain what situation you are in, your posts are unclear.
-
@john_hobbyist said in Pop-up with colors and data:
My concern now is how do I delete the existing layout manager?
Why do you want to delete if you do not get an error message? If you do get an error message, I asked you where it came from? I am totally uncertain what situation you are in, your posts are unclear.
@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??
-
@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? -