如何在PyQt中制作白盒?

时间:2013-05-13 18:53:21

标签: python qt pyqt4

我有一个PyQt应用程序,它有一个名为Deck的小部件

class Deck(QtGui.QWidget):

    def __init__(self, filename, parent):
        super(Deck, self).__init__(parent)

        self.setMinimumSize(100, 150)
        self.setStyleSheet('background-color: white;')

        label = QtGui.QLabel("deck", self)
        label.show()

我希望Deck小部件全部为白色,但它只在标签下,虽然它接受100x150区域的点击并调整其hbox:s大小。

enter image description here

编辑: 周围的布局。

import sys
from PyQt4 import QtGui

app = QtGui.QApplication(sys.argv)
#import qt4reactor
#qt4reactor.install()

from deck import Deck

class Duel(QtGui.QWidget):
    def __init__(self):
        super(Duel, self).__init__()

        topArea = QtGui.QHBoxLayout()
        topArea.addStretch(1)
        d = Deck(sys.argv[1], self)
        d.show()
        topArea.addWidget(d)

        bottomArea = QtGui.QHBoxLayout()
        d = Deck(sys.argv[2], self)
        d.show()
        bottomArea.addWidget(d)
        bottomArea.addStretch(1)

        vbox = QtGui.QVBoxLayout()
        vbox.addLayout(topArea)
        vbox.addStretch(1)
        vbox.addLayout(bottomArea)
        self.setLayout(vbox)


def main():
    root = Duel()
    root.show()

    app.exec_()

if __name__ == '__main__':
    main()

0 个答案:

没有答案