如何在 QWidget 周围添加边框? [英] How to add border around QWidget?

查看:572
本文介绍了如何在 QWidget 周围添加边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 PyQT4 为潜在客户创建示例应用程序.我正在寻找某种方法来在特定小部件周围放置边框.请给我一些寻找的指示.

I am using PyQT4 to create a sample application for a prospective client. I am looking for some way to put a border around a specific widget. Please give me some pointers to look for.

更新:

class CentralWidget(QtGui.QWidget):

    def __init__(self, mainWindow):
        super(CentralWidget, self).__init__()

        self.create(mainWindow)

以上代码定义了小部件.

Above code defines the widget.

推荐答案

根据样式表文档,QWidget 不支持边框属性.

According to the stylesheet documentation, QWidget does not support the border property.

你必须使用类似 QFrame 的东西:

You have to use something like a QFrame:

这是一个完整的例子

from PyQt4 import QtGui,QtCore

class CentralWidget(QtGui.QFrame):

    def __init__(self, *args):
        super(CentralWidget, self).__init__(*args)
        self.setStyleSheet("background-color: rgb(255,0,0); margin:5px; border:1px solid rgb(0, 255, 0); ")

if __name__ == '__main__':
    import sys
    app = QtGui.QApplication(sys.argv)
    mw = QtGui.QMainWindow()
    w = CentralWidget(mw)
    mw.setCentralWidget(w)
    mw.show()
    w.show()
    app.exec_()

这篇关于如何在 QWidget 周围添加边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆