1 Star 0 Fork 1

OpenCG/smart_qtwidgets

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
thumbnail_item_base_widget.py 3.06 KB
一键复制 编辑 原始数据 按行查看 历史
sheen 提交于 2021-08-30 15:41 . update
# coding=utf-8
from functools import partial
from qtpy import QtWidgets, QtCore
from .ui.thumbnail_item_row_widget import Ui_thumbnail_item_row_widget
class ThumbnailItemBaseWidget(QtWidgets.QWidget):
def __init__(self, widget_factory, parent):
QtWidgets.QWidget.__init__(self, parent)
self._ui = widget_factory()
self._ui.setupUi(self)
self._ui.thumbnail.setScaledContents(False)
# self._ui.box.setProperty('item_type', 'thumbnail')
self._ui.box.setProperty('item_status', 'normal')
# 设置菜单
self._menu = QtWidgets.QMenu(self)
self._actions = []
# self._ui.action_btn.setMenu(self._menu)
self._ui.action_btn.setVisible(False)
# self._menu.setStyleSheet("""QMenu{
# color:rgb(200,200,200);
# font: 9pt \"Arial\";
# background:rgb(35,35,35);
# border: 1px solid rgb(0, 120, 215);
# }
# QMenu:item:disabled{
# color:rgba(50,50,50);
# }
# QMenu:item:disabled:selected{
# background:rgba(0, 120, 215, 30);
# color:rgba(50,50,50);
# }
# QMenu:item:selected{
# background:rgb(0, 120, 215);
# }
# """)
def menu_enable(self, status):
if status:
self._ui.action_btn.setMenu(self._menu)
else:
self._ui.action_btn.setMenu(None)
def set_actions(self, actions, hook, data):
"""
添加菜单
"""
self._actions = actions
name_list = self._actions.keys()
for name in name_list:
cmd = self._actions[name]
action = QtWidgets.QAction(name, self)
action.triggered.connect(partial(hook.main, cmd, data))
self._menu.addAction(action)
def set_border_radius(self, status):
self._ui.box.setProperty('border_radius', status)
def set_action_btn_visible(self, is_visible):
"""
菜单按钮的显示
"""
self._ui.action_btn.setVisible(is_visible)
def set_thumbnail(self, pixmap):
"""
设置预览图片
"""
self._ui.thumbnail.setPixmap(pixmap)
def set_status(self, status='normal'):
self._ui.box.setProperty('item_status', status)
self._ui.box.style().polish(self._ui.box)
self._ui.box.update()
@staticmethod
def calculate_size(width, height):
return QtCore.QSize(width, height)
def set_selected(self, value):
if value:
self.set_status('selected')
else:
self.set_status('normal')
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/tdercg/smart_qtwidgets.git
git@gitee.com:tdercg/smart_qtwidgets.git
tdercg
smart_qtwidgets
smart_qtwidgets
master

搜索帮助