记录PyQt点点滴滴
self.setWindowFlags(Qt.FramelessWindowHint | Qt.WindowSystemMenuHint | Qt.WindowMinimizeButtonHint)
# 第一个参数是设置无边框。
# 第二个参数是允许任务栏按钮右键菜单,
# 第三个参数是允许最小化与还原。
然后;
self.showMaximized() # 最小化
self.showMinimized() # 最大化
pkexec env DISPLAY=$DISPLAY XAUTHORITY=$XAUTHORITY /opt/bin/client/client_run.sh
client_run.sh 为启动脚本
lupdate -verbose *.cpp -ts fileName_zh.ts
linguist-qt4 fileName_zh_CN.ts
lrelease-qt4 fileName_zh_CN.ts
#!/usr/bin/env python
#coding=utf-8
from PyQt4.QtCore import Qt
from PyQt4.QtGui import QDialog, QPainter, QColor
class Dialog(QDialog):
def __init__(self,parent = None):
super(Dialog, self).__init__(parent)
self.setAttribute(Qt.WA_TranslucentBackground, True) # 一定要有
self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint
| Qt.WindowSystemMenuHint | Qt.WindowMinimizeButtonHint
| Qt.WindowMaximizeButtonHint)
self.move(100,100)
self.setFixedSize(500,300)
def paintEvent(self, paintEvent):
painter = QPainter(self)
painter.setBrush(QColor("#CCCCFF"))
painter.setPen(QColor("#00FF00"))
# painter.setRenderHint(QPainter.Antialiasing) ## 抗锯齿
painter.drawRoundedRect(0,0,self.width()-1,self.height() -1,20,20)
if __name__ == '__main__':
from PyQt4.QtGui import QApplication
import sys
app = QApplication(sys.argv)
dlg = Dialog()
dlg.show()
app.exec_()
QPainterPath path;
QRectF rect = QRectF(0,0,480,640);
path.addRoundRect(rect,5,5);
QPolygon polygon= path.toFillPolygon().toPolygon();//获得这个路径上的所有的点
QRegion region(polygon);//根据这些点构造这个区域
setMask(region);
path = QPainterPath()
rect = QRectF(0,0,self.width(),self.height())
path.addRoundedRect(rect,10,10)
polygon = path.toFillPolygon().toPolygon()
region = QRegion(polygon)
self.setMask(region)
或者
class Dialog(QDialog):
def __init__(self,parent = None):
super(Dialog, self).__init__(parent)
self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint
| Qt.WindowSystemMenuHint | Qt.WindowMinimizeButtonHint
| Qt.WindowMaximizeButtonHint)
self.move(100,100)
self.setFixedSize(500,300)
self.bitmap = QBitmap(self.size()) #生成一张位图
painter = QPainter(self.bitmap) #QPainter用于在位图上绘画
painter.fillRect(self.rect(),Qt.white) #填充位图矩形框(用白色填充)
painter.setBrush(QColor(0,0,0)) #黑色Brush
painter.setRenderHint(QPainter.Antialiasing)
painter.drawRoundedRect(self.rect(),50,50) #在位图上画圆角矩形(用黑色填充)
#
self.setMask(self.bitmap) #使用setmask过滤即可
setStyleSheet(
"QPushButton { background-color:#FFFFFF;"
"color:#000000;"
"border-color:#FFFFFF;"
"font:bold 15pt;" # 字体大小
"border-width:2px;"
"border-style:solid;" # 实线
"border-radius:8px;" # 圆角
"}"
"QPushButton:hover{ "
"background:red;"
"color:#FFFFFF;"
"border-color:red;"
"border-width:2px;"
"border-style:solid;"
"border-radius:8px;"
"}"
"QPushButton:pressed{"
"background: #FF0000;"
"border-color:#3f78ad;"
"border-width:2px;"
"border-style:solid;"
# "border-radius:8px;"
"}"
)
//在Widget的.h文件中
void mouseMoveEvent(QMouseEvent*event);
void mousePressEvent(QMouseEvent*event);
void mouseReleaseEvent(QMouseEvent*event);
QPointdrag Position;
//在Widget的.cpp文件中
void LoginDialog::mouseReleaseEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
dragPosition = QPoint(-1, -1);
event->accept();
}
}
void LoginDialog::mousePressEvent(QMouseEvent *event)
{
if (event->button() == Qt::LeftButton)
{
dragPosition = event->globalPos() - frameGeometry().topLeft();
event->accept();
}
}
void LoginDialog::mouseMoveEvent(QMouseEvent *event)
{
if (event->buttons() &Qt::LeftButton)
{
if (dragPosition != QPoint(-1, -1))
move(event->globalPos() - dragPosition);
event->accept();
}
}
from PyQt4.QtCore import Qt, QPoint
from PyQt4.QtGui import QDialog
class Dialog(QDialog):
def __init__(self,parent = None):
super(Dialog, self).__init__(parent)
self.setWindowFlags(Qt.Window | Qt.FramelessWindowHint
| Qt.WindowSystemMenuHint | Qt.WindowMinimizeButtonHint
| Qt.WindowMaximizeButtonHint)
self.setFixedSize(500,300)
self.__dragPosition = QPoint(-1, -1)
def mouseReleaseEvent(self, event):
if event.button() == Qt.LeftButton :
self.__dragPosition = QPoint(-1, -1)
event.accept()
def mousePressEvent(self, event):
if (event.button() == Qt.LeftButton):
self.__dragPosition = event.globalPos() - self.frameGeometry().topLeft()
event.accept()
def mouseMoveEvent(self ,event):
if (event.buttons() & Qt.LeftButton):
if (self.__dragPosition != QPoint(-1, -1)):
self.move(event.globalPos() - self.__dragPosition)
event.accept()
if __name__ == '__main__':
from PyQt4.QtGui import QApplication
import sys
app = QApplication(sys.argv)
dlg = Dialog()
dlg.show()
app.exec_()
QT之鼠标样式
python列表和QVariant