Pop-up with colors and data
-
Hello, how can I make a pop-up that on the left will have different colors in rectangles and on the right words/data?? I attach a file for help...
-
Hello, how can I make a pop-up that on the left will have different colors in rectangles and on the right words/data?? I attach a file for help...
@john_hobbyist
Nothing special for it being a "pop-up". Just a widget with layoutsQHBoxLayout
&QVBoxLayout
, or aQGridLayout
if you prefer. -
How do I color the boxes?
-
How do I color the boxes?
-
@eyllanesc Thanks! Yes, but it fills the background. I need to color the box inside...
-
@eyllanesc Thanks! Yes, but it fills the background. I need to color the box inside...
@john_hobbyist I am assuming that the box is a QWidget. If you want more help then show your progress.
-
I found this: https://www.geeksforgeeks.org/pyqt5-how-to-change-background-color-of-main-window/ How can I transform it for filling the box color?
-
I found this: https://www.geeksforgeeks.org/pyqt5-how-to-change-background-color-of-main-window/ How can I transform it for filling the box color?
@john_hobbyist QLabel is a QWidget then use
self.label.setStyleSheet("border: 1px solid black; background-color: red")
-
This is my try, by modifying the above code and this example: https://www.tutorialspoint.com/pyqt/pyqt_qgridlayout_class.htm ! Where do I put this line of code:
self.label.setStyleSheet("border: 1px solid black; background-color: red")
in order to color the boxes? I tried also with self. etc nothing!
import sys from PyQt5.QtCore import * from PyQt5.QtWidgets import * def window(): 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_()) if __name__ == '__main__': window()
-
This is my try, by modifying the above code and this example: https://www.tutorialspoint.com/pyqt/pyqt_qgridlayout_class.htm ! Where do I put this line of code:
self.label.setStyleSheet("border: 1px solid black; background-color: red")
in order to color the boxes? I tried also with self. etc nothing!
import sys from PyQt5.QtCore import * from PyQt5.QtWidgets import * def window(): 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_()) if __name__ == '__main__': window()
@john_hobbyist Change:
grid.addWidget(QLabel("Yellow"), 1,1)
to
label_yellow = QLabel("Yellow") label_yellow.setStyleSheet(...) grid.addWidget(label_yellow, 1,1)
-
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.