在PyQt4中在新窗口中制作qwidget
我正在尝试创建一个扩展 qwidget 的类,该类会弹出一个新窗口,我必须缺少一些基本的东西,
class NewQuery(QtGui.QWidget):
def __init__(self, parent):
QtGui.QMainWindow.__init__(self,parent)
self.setWindowTitle('Add New Query')
grid = QtGui.QGridLayout()
label = QtGui.QLabel('blah')
grid.addWidget(label,0,0)
self.setLayout(grid)
self.resize(300,200)
当在主窗口的类中创建该类的新实例并调用 show() 时,内容将覆盖在主窗口,如何让它显示在新窗口中?
I'm trying to make a class that extends qwidget, that pops up a new window, I must be missing something fundamental,
class NewQuery(QtGui.QWidget):
def __init__(self, parent):
QtGui.QMainWindow.__init__(self,parent)
self.setWindowTitle('Add New Query')
grid = QtGui.QGridLayout()
label = QtGui.QLabel('blah')
grid.addWidget(label,0,0)
self.setLayout(grid)
self.resize(300,200)
when a new instance of this is made in main window's class, and show() called, the content is overlaid on the main window, how can I make it display in a new window?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
遵循 @ChristopheD 给你的建议并尝试这个
follow the advice that @ChristopheD gave you and try this instead
您的超类初始值设定项是错误的,您可能的意思是:(
使用
super
的原因):但也许您想从
QtGui.QDialog
继承(这可能是合适的 - 很难结合当前上下文来判断)。另请注意,代码示例中的缩进是错误的(单个空格即可,但 4 个空格或单个制表符被认为更好)。
Your superclass initialiser is wrong, you probably meant:
(a reason to use
super
):But maybe you want inherit from
QtGui.QDialog
instead (that could be appropriate - hard to tell with the current context).Also note that the indentation in your code example is wrong (a single space will work but 4 spaces or a single tab are considered nicer).