1022 views|3 replies

4

Posts

0

Resources
The OP
 

Problem creating two windows with parent-child relationship when using pyqt5 [Copy link]

First, I created two QWidget objects, then set the parent-child relationship and the corresponding background color. I observed that the background color of the parent object surrounded the child object. However, I wrote a class that completely inherited from QWidget, which did not work. I could only see the background color of the parent object. from PyQt5.Qt import *

class Window(QWidget):
def __init__(self):
super().__init__()

if __name__ == '__main__':
import sys
qApp = QApplication(sys.argv)
window = Window()
window.setStyleSheet("background-color:yellow")
window.resize(500,500)
window.setWindowTitle("jiuzhe ")

window1 = Window()
window1.setStyleSheet("background-color:red")
window1.resize(300,300)
window1.move(0,0)
window1.setParent(window)

print(window)
print(window1.parent())

window.show()
window1.show()
sys.exit(qApp.exec())

Latest reply

Correct answer. It seems that you have a very good foundation in pyqt. Thanks for the answer.   Details Published on 2023-3-17 08:17
 
 

4771

Posts

12

Resources
2
 

Class inheritance

 
 
 

46

Posts

0

Resources
3
 

Because it inherits from QWidget, it of course inherits the parent object, so you can see the background color of the parent object.


Comments

Correct answer. It seems that you have a very good foundation in pyqt. Thanks for the answer.  Details Published on 2023-3-17 08:17
 
 
 

6841

Posts

11

Resources
4
 
no814987 Published on 2023-3-17 06:49 Because it inherits from QWidget, it inherits the parent object, so you can see the background color of the parent object.

Correct answer. It seems that you have a very good foundation in pyqt. Thanks for the answer.

 
 
 

Just looking around
Find a datasheet?

EEWorld Datasheet Technical Support

Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号
快速回复 返回顶部 Return list