隐藏状态栏,自己写缩小关闭的按钮,实现窗口拖动
self. setWindowFlags( QtCore. Qt. FramelessWindowHint)
self. pushButton_3. clicked. connect( self. close)
self. pushButton_2. clicked. connect( self. showMinimized)
def mousePressEvent ( self, event) :
if event. button( ) == QtCore. Qt. LeftButton:
self. m_flag = True
self. m_Position = event. globalPos( ) - self. pos( )
event. accept( )
self. setCursor( QtGui. QCursor( QtCore. Qt. OpenHandCursor) )
def mouseMoveEvent ( self, QMouseEvent) :
if QtCore. Qt. LeftButton and self. m_flag:
self. move( QMouseEvent. globalPos( ) - self. m_Position)
QMouseEvent. accept( )
def mouseReleaseEvent ( self, QMouseEvent) :
self. m_flag = False
self. setCursor( QtGui. QCursor( QtCore. Qt. ArrowCursor) )
静态启动界面(解决鼠标点击消失的bug)
import sys
import time
from PyQt5. QtCore import Qt
from PyQt5. QtGui import QFont, QPixmap
from PyQt5. QtWidgets import QSplashScreen, qApp
class SplashPanel ( QSplashScreen) :
def __init__ ( self) :
super ( SplashPanel, self) . __init__( )
message_font = QFont( )
message_font. setBold( True )
message_font. setPointSize( 14 )
self. setFont( message_font)
pixmap = QPixmap( "C:/Users/Administrator/Desktop/login_picture/start.jpg" )
self. setPixmap( pixmap)
self. show( )
for i in range ( 1 , 5 ) :
self. showMessage( '正在打开应用{}' . format ( '.' * i) , alignment= Qt. AlignBottom, color= Qt. black)
time. sleep( 0.15 )
def mousePressEvent ( self, evt) :
pass
def mouseDoubleClickEvent ( self, * args, ** kwargs) :
pass
def enterEvent ( self, * args, ** kwargs) :
pass
def mouseMoveEvent ( self, * args, ** kwargs) :
pass
if __name__ == "__main__" :
app = QtWidgets. QApplication( sys. argv)
splash = SplashPanel( )
qApp. processEvents( )
demo = ex( )
demo. show( )
splash. finish( demo)
splash. deleteLater( )
sys. exit( app. exec_( ) )
将cv2读取的图片保存至Qlabel上
opencv_img = cv2. imread( 文件路径, 1 )
if opencv_img is None :
print ( 'None' )
else :
size = ( int ( self. label名字. width( ) ) , int ( self. label名字. height( ) ) )
shrink = cv2. resize( opencv_img, size, interpolation= cv2. INTER_AREA)
shrink = cv2. cvtColor( shrink, cv2. COLOR_BGR2RGB)
self. QtImg = QtGui. QImage( shrink. data,
shrink. shape[ 1 ] ,
shrink. shape[ 0 ] ,
shrink. shape[ 1 ] * 3 ,
QtGui. QImage. Format_RGB888)
self. label名字. setPixmap( QtGui. QPixmap. fromImage( self. QtImg) )
解决cv2无法读取带中文路径文件
opencv_img = cv2. imdecode( np. fromfile( 文件路径, dtype= np. uint8) , 1 )
python的列表当成字段上传到mysql数据库需要的转换
def deal ( ) :
# 假设a需要保存到mysql
a = [ 0 , 1 , 0 , 0 , 1 ]
b = ',' . join ( [ str ( x) for x in a] ) # 转化为str直接写入到mysql
c = [ int ( i) for i in ( b. split ( ',' ) ) ] # mysql中读取出来再转化为list使用