赞
踩
python
os.path.exists(a_pathFile)
获取python系统路径
import distutils.sysconfig
distutils.sysconfig.get_python_lib(True)
BASE_EXEC_PREFIX = r'C:\Users\Win_Lin\AppData\Local\Programs\Python\Py...
BASE_PREFIX = r'C:\Users\Win_Lin\AppData\Local\Programs\Python\Python3...
EXEC_PREFIX = r'C:\Users\Win_Lin\AppData\Local\Programs\Python\Python3...
PREFIX = r'C:\Users\Win_Lin\AppData\Local\Programs\Python\Python36-32'
鼠标跟踪 配合QMouseMoveEvent
self.setMouseTracking(True);
self.centralWidget.setMouseTracking(True);
#鼠标穿透
self.setAttribute(Qt.WA_TransparentForMouseEvents,True);
#widget背景样式不被父窗体覆盖
self.setAttribute(Qt.WA_StyledBackground, True);
#窗体模态
self.setWindowModality(Qt.ApplicationModal);
header 1 | header 2 | header 3 |
---|---|---|
Qt::NonModal | 0 | The window is not modal and does not block input to other windows. |
Qt::ApplicationModal | 2 | The window is modal to the application and blocks input to all windows. |
Qt::WindowModal | 1 | The window is modal to a single window hierarchy and blocks input to its parent window, all grandparent windows, and all siblings of its parent and grandparent windows. |
self.setWindowModality()
QWidget::setAttribute(Qt::WA_TransparentForMouseEvents,true);
msg=QMessageBox.warning(self, '请确认', '已满10条,是否重新开始?',
QMessageBox.Yes|QMessageBox.No, QMessageBox.No)
if msg==QMessageBox.Yes:
#ToDo
elif msg==QMessageBox.No:
msg=QMessageBox.warning(self, '生成脚本', '开始生成脚本。',
QMessageBox.Yes|QMessageBox.No, QMessageBox.Yes)
if msg==QMessageBox.Yes:
#ToDo
elif msg==QMessageBox.No:
#ToDo
import traceback
from PyQt5 import QtGui, QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
def showERROR():
def _doWhat(fun)
try:
func()
except:
errmsg = traceback.format_exc()
QMessageBox.warning(QWidget(), '请确认', errmsg,
QMessageBox.Ok)
return _doWhat()
#只读
self.setEditTriggers(QAbstractItemView.NoEditTriggers);
header 1 | header 2 | header 3 | header 4 |
---|---|---|---|
QHeaderView::Interactive | 0 | 可拉伸,默认 | 用户可设置,也可被程序设置成默认大小 |
QHeaderView::Fixed | 2 | 不可拉,等宽 | 用户不可更改列宽 |
QHeaderView::Stretch | 1 | 不可拉 | 根据空间,自动改变列宽,用户与程序不能改变列宽 |
QHeaderView::ResizeToContents | 3 | 不可拉,根据内容调整 | 根据内容改变列宽,用户与程序不能改变列宽 |
self.horizontalHeader().setSectionResizeMode(3)#列宽设置
self.horizontalHeader().setStretchLastSection(True); #充满列宽
self.verticalHeader().setSectionResizeMode(1)#行高设置
self.verticalHeader().setStretchLastSection(True); #充满行高
self.tableWidget.setSelectionBehavior(QTableWidget.SelectRows)#行选择模式
self.tableWidget.setSelectionMode(QAbstractItemView.SingleSelection);#无法拖拽选择
self.tableWidget.setContextMenuPolicy(Qt.CustomContextMenu) #弹出菜单
self.tableWidget.customContextMenuRequested.connect(self.myListWidgetContext)#右键请求
def myListWidgetContext(self):
popMenu =QMenu()
popMenu.addAction(u'删除行',lambda:self.del_Item(1))
popMenu.exec_(QCursor.pos())#鼠标位置
def del_Item(self, type=1):
for model_index in self.tableWidget.selectionModel().selectedRows():
index = QtCore.QPersistentModelIndex(model_index)
self.tableWidget.removeRow(index.row())
# Listwidget
def del_Item(self, type=1):
for model_index in self.listWidget.selectedItems():
row = self.listWidget.indexFromItem(model_index).row()
self.listWidget.takeItem(row);
self.spacer.changeSize(100, 20, QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Minimum)#改变弹簧长度
self.Layout.invalidate()# 重新布局
app = QtWidgets.QApplication(sys.argv)
app.setStyle(QStyleFactory.create("Fusion"))
import qdarkstyle
app.setStyleSheet(qdarkstyle.load_stylesheet_pyqt5())
ui = MainWindow()
styleFile = './style.css'
qssStyle = CommonHelper.readQss( styleFile )
ui.setStyleSheet( qssStyle )
ui.show()
self.statusBar.showMessage(" 菜单选项被点击了", msec=5000)
self.statusBar.addWidget(*QWidget)#加到左下角
self.statusBar.addPermanentWidget(*QWidget)#加到右下角
https://blog.csdn.net/cqltbe131421/article/details/78646228
self.buttonGroup.checkedButton().text(),
self.pixmap=QPixmap()
self.pixmap.load(':/image/main.jpg')
def paintEvent(self, e):
painter=QPainter(self) ;
painter.drawPixmap(0,0,self.width(), self.height(), self.pixmap);
self.b1.setText(“\uf0b1”+ “\n”*line+ “你好啊”)
self.b2.setText(“\uf0e8”+ “\n”*line+ “你好啊”)
self.b3.setText(“\uf0f0”+ “\n”*line+ “你好啊”)
self.b4.setText(“\uf0ad”+ “\n”*line+ “你好啊”)
if __name__ == "__main__":
import sys
app = QApplication(sys.argv)
app.setStyle(QStyleFactory.create("Fusion"))
fontId = QFontDatabase.addApplicationFont(":/image/fontawesome-webfont.ttf")
fontName = QFontDatabase.applicationFontFamilies ( fontId )[0]
app.setFont(QFont(fontName, 15));
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。