pyqt5界面制作模块(1)

1.背景统一颜色,不影响内部控件:

#frame{
    background-color: rgb(255, 255, 255);
    border: 5px, white;
    border-radius: 4px;
    margin: 5px;
}

  其中#frame{ }表示样式表只作用于frame, 不会对于frame的子类进行继承;

  background-color表示背景色, rgb(255, 255, 255)为白色;

  border表示边框, 边框线为5px, 边框线为白色white;

  border-radius表示边框角为圆角, 圆角半径为4px

  margin表示边框的空白, 空白的长度为5px;

2.最小化按键样式表:

QPushButton{
    background-color: rgb(255, 255, 255);
    font: 15pt "宋体" ;
    border:none;
    border-radius:none;    
    color: gray;
}
 
QPushButton:hover{
    background-color: rgb(218, 218, 218);
}
 
QToolTip{
    background-color: rgb(255, 255, 255);
}

3.关闭按键样式表:

QPushButton{
    background-color: rgb(255, 255, 255);
    font: 10pt "宋体" ;
    border:none;
    border-top-right-radius:4px;
    border-top-left-radius:0px;
    border-bottom-right-radius:0px;
    border-bottom-left-radius:0px;
    color: gray;
}
 
QPushButton:hover{
    background-color: rgb(218, 218, 218);
}
 
QToolTip{
    background-color: rgb(255, 255, 255);
}

4.一般按钮设置,三个状态:常规,鼠标悬浮,点击:

QPushButton{
image: url(:/Phone.png);
background-color:#f8f8f7;
border:2px solid white;
border-radius:25px;
}
QPushButton:hover{
border:2px #b0b0b0;
background-color:#dfdfdf;
}
QPushButton:pressed{
background-color: rgb(255, 255, 255);
}

5.在self.UntitledUi.setupUi(self)下方添加如下代码实现无边框和阴影效果:

self.setWindowFlag(Qt.FramelessWindowHint)        #将界面设置为无框
self.setAttribute(Qt.WA_TranslucentBackground)    #将界面属性设置为半透明
self.shadow = QGraphicsDropShadowEffect()        #设定一个阴影,半径为10,颜色为#444444,定位为0,0
self.shadow.setBlurRadius(10)
self.shadow.setColor(QColor("#444444"))
self.shadow.setOffset(0, 0)
self.UntitledUi.frame.setGraphicsEffect(self.shadow)    #为frame设定阴影效果

6.鼠标事件,实现鼠标拖动窗口:

def mousePressEvent(self, event):        #鼠标左键按下时获取鼠标坐标,按下右键取消
    if event.button() == Qt.LeftButton:
        self.m_flag = True
        self.m_Position = event.globalPos() - self.pos()
        event.accept()
    elif event.button() == Qt.RightButton:
        self.m_flag = False
 
def mouseMoveEvent(self, QMouseEvent):    #鼠标在按下左键的情况下移动时,根据坐标移动界面
    if Qt.LeftButton and self.m_flag:
        self.move(QMouseEvent.globalPos() - self.m_Position)
        QMouseEvent.accept()
 
def mouseReleaseEvent(self, QMouseEvent):    #鼠标按键释放时,取消移动
    self.m_flag = False

 

posted @ 2023-02-21 15:54  潭下月清影  阅读(36)  评论(0)    收藏  举报