PyQt 边框式样

PyQt 边框式样主要包括以下几种:

PyQt 边框式样
(图片来源网络,侵删)

1、QFrame.Sunken:凹陷式边框,边框在内容区域之外。

2、QFrame.Raised:凸起式边框,边框在内容区域之上。

3、QFrame.Box:默认边框样式,边框在内容区域之内。

4、QFrame.Panel:面板式边框,边框在内容区域之外,但比凹陷式边框更窄。

5、QFrame.StyledPanel:带有阴影的面板式边框。

6、QFrame.WinPanel:Windows风格的面板式边框。

7、QFrame.HLine:水平线边框。

8、QFrame.VLine:垂直线边框。

9、QFrame.StyledFrame:带有圆角和阴影的边框。

10、QFrame.NoFrame:无边框样式。

以下是一个简单的 PyQt 边框式样示例:

import sys
from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QFrame
from PyQt5.QtCore import Qt
class Example(QWidget):
    def __init__(self):
        super().__init__()
        self.initUI()
    def initUI(self):
        vbox = QVBoxLayout()
        # 创建不同样式的边框
        frame1 = QFrame(self)
        frame1.setFrameShape(QFrame.Sunken)
        frame1.setLineWidth(2)
        frame1.setMidLineWidth(1)
        frame1.setStyleSheet("bordercolor: red;")
        frame2 = QFrame(self)
        frame2.setFrameShape(QFrame.Raised)
        frame2.setLineWidth(2)
        frame2.setMidLineWidth(1)
        frame2.setStyleSheet("bordercolor: blue;")
        frame3 = QFrame(self)
        frame3.setFrameShape(QFrame.Box)
        frame3.setLineWidth(2)
        frame3.setMidLineWidth(1)
        frame3.setStyleSheet("bordercolor: green;")
        frame4 = QFrame(self)
        frame4.setFrameShape(QFrame.Panel)
        frame4.setLineWidth(2)
        frame4.setMidLineWidth(1)
        frame4.setStyleSheet("bordercolor: purple;")
        # 将按钮添加到不同的边框中
        button1 = QPushButton("按钮1", self)
        button1.setGeometry(50, 50, 100, 30)
        frame1.addWidget(button1)
        button2 = QPushButton("按钮2", self)
        button2.setGeometry(50, 90, 100, 30)
        frame2.addWidget(button2)
        button3 = QPushButton("按钮3", self)
        button3.setGeometry(50, 130, 100, 30)
        frame3.addWidget(button3)
        button4 = QPushButton("按钮4", self)
        button4.setGeometry(50, 170, 100, 30)
        frame4.addWidget(button4)
        vbox.addWidget(frame1)
        vbox.addWidget(frame2)
        vbox.addWidget(frame3)
        vbox.addWidget(frame4)
        self.setLayout(vbox)
        self.setWindowTitle('PyQt 边框式样')
        self.show()
if __name__ == '__main__':
    app = QApplication(sys.argv)
    ex = Example()
    sys.exit(app.exec_())

在这个示例中,我们创建了四个不同样式的边框(凹陷式、凸起式、默认样式和面板式),并将四个按钮添加到这些边框中,通过运行这个程序,你可以看到不同样式的边框效果。

原创文章,作者:未希,如若转载,请注明出处:https://www.kdun.com/ask/478339.html

(0)
未希新媒体运营
上一篇 2024-04-15 11:36
下一篇 2024-04-15 11:37

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

云产品限时秒杀。精选云产品高防服务器,20M大带宽限量抢购  >>点击进入