提交 88110fb5 编写于 作者: 之一Yo's avatar 之一Yo

修复下拉框重复弹出菜单的问题

上级 315fdcb6
......@@ -5,6 +5,7 @@ from qfluentwidgets import (SettingCardGroup, SwitchSettingCard, FolderListSetti
ComboBoxSettingCard, ExpandLayout, Theme, ToastToolTip, CustomColorSettingCard,
setTheme, setThemeColor, RangeSettingCard, isDarkTheme)
from qfluentwidgets import FluentIcon as FIF
from qfluentwidgets import InfoBar
from PyQt5.QtCore import Qt, pyqtSignal, QUrl, QStandardPaths
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtWidgets import QWidget, QLabel, QFileDialog
......@@ -194,10 +195,11 @@ class SettingInterface(ScrollArea):
def __showRestartTooltip(self):
""" show restart tooltip """
ToastToolTip.warn(
self.tr('Configuration updated successfully'),
InfoBar.success(
self.tr('Updated successfully'),
self.tr('Configuration takes effect after restart'),
self.window()
duration=1500,
parent=self
)
def __onDownloadFolderCardClicked(self):
......
......@@ -57,7 +57,7 @@ class StatusInfoInterface(GalleryInterface):
infoBar = InfoBar(
icon=InfoBarIcon.SUCCESS,
title=self.tr('Success'),
content=self.tr("Essential app message for your users."),
content=self.tr("The Anthem of man is the Anthem of courage."),
orient=Qt.Horizontal,
isClosable=True,
duration=-1,
......@@ -71,7 +71,7 @@ class StatusInfoInterface(GalleryInterface):
)
# long info bar
content = self.tr("A long essential app message for your users to be informed of, acknowledge, or take action on. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dapibus dolor vitae justo rutrum, ut lobortis nibh mattis. Aenean id elit commodo, semper felis nec.")
content = self.tr("My name is kira yoshikake, 33 years old. Living in the villa area northeast of duwangting, unmarried. I work in Guiyou chain store. Every day I have to work overtime until 8 p.m. to go home. I don't smoke. The wine is only for a taste. Sleep at 11 p.m. for 8 hours a day. Before I go to bed, I must drink a cup of warm milk, then do 20 minutes of soft exercise, get on the bed, and immediately fall asleep. Never leave fatigue and stress until the next day. Doctors say I'm normal.")
infoBar = InfoBar(
icon=InfoBarIcon.WARNING,
title=self.tr('Warning'),
......@@ -99,7 +99,7 @@ class StatusInfoInterface(GalleryInterface):
position=InfoBarPosition.NONE,
parent=self
)
infoBar.addWidget(PushButton('Action'))
infoBar.addWidget(PushButton(self.tr('Action')))
infoBar.setCustomBackgroundColor("white", "#202020")
self.addExampleCard(
self.tr('An InfoBar with custom icon, background color and widget.'),
......@@ -147,25 +147,21 @@ class StatusInfoInterface(GalleryInterface):
self.stateTooltip.show()
def createInfoInfoBar(self):
content = "A long essential app message for your users to be informed of, acknowledge, or take action on. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin dapibus dolor vitae justo rutrum, ut lobortis nibh mattis. Aenean id elit commodo, semper felis nec."
w = InfoBar(
icon=InfoBarIcon.INFORMATION,
title='Information',
content=content,
orient=Qt.Vertical, # vertical layout
InfoBar.info(
title=self.tr('Lesson 3'),
content=self.tr("Believe in the spin, just keep believing!"),
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP_RIGHT,
duration=2000,
parent=self
)
w.show()
def createSuccessInfoBar(self):
content = "A short essential success app message."
# convenient static mothod
InfoBar.success(
title='Title',
content=content,
title=self.tr('Lesson 4'),
content=self.tr("With respect, let's advance towards a new stage of the spin."),
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.TOP,
......@@ -175,8 +171,8 @@ class StatusInfoInterface(GalleryInterface):
def createWarningInfoBar(self):
InfoBar.warning(
title='Title',
content="A short essential app warning message.",
title=self.tr('Lesson 5'),
content=self.tr("迂回路を行けば最短ルート。"),
orient=Qt.Horizontal,
isClosable=False, # disable close button
position=InfoBarPosition.TOP_LEFT,
......@@ -187,7 +183,7 @@ class StatusInfoInterface(GalleryInterface):
def createErrorInfoBar(self):
InfoBar.error(
title=self.tr('No Internet'),
content="A error message which won't disappear automatically.",
content=self.tr("An error message which won't disappear automatically."),
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
......
# coding:utf-8
from PyQt5.QtCore import Qt, pyqtSignal, QRect, QRectF, QPoint
from PyQt5.QtGui import QColor, QPainter
from PyQt5.QtGui import QColor, QPainter, QCursor
from PyQt5.QtWidgets import QAction, QPushButton, QWidget
from .menu import RoundMenu
......@@ -21,6 +21,7 @@ class ComboBox(QPushButton):
self.isPressed = False
self.items = []
self._currentIndex = -1
self.dropMenu = None
setStyleSheet(self, 'combo_box')
def addItem(self, text):
......@@ -119,7 +120,23 @@ class ComboBox(QPushButton):
super().mouseReleaseEvent(e)
self.isPressed = False
self.update()
self._showComboMenu()
if self.dropMenu:
self._closeComboMenu()
else:
self._showComboMenu()
def _closeComboMenu(self):
if not self.dropMenu:
return
self.dropMenu.close()
self.dropMenu = None
def _onDropMenuClosed(self):
pos = self.mapFromGlobal(QCursor.pos())
if not self.rect().contains(pos):
self.dropMenu = None
def _showComboMenu(self):
if not self.items:
......@@ -133,6 +150,9 @@ class ComboBox(QPushButton):
menu.view.setMinimumWidth(self.width())
menu.adjustSize()
menu.closedSignal.connect(self._onDropMenuClosed)
self.dropMenu = menu
# set the selected item
menu.setDefaultAction(menu.menuActions()[self.currentIndex()])
......
......@@ -174,6 +174,8 @@ class MenuActionListWidget(QListWidget):
class RoundMenu(QWidget):
""" Round corner menu """
closedSignal = pyqtSignal()
def __init__(self, title="", parent=None):
super().__init__(parent=parent)
self._title = title
......@@ -491,6 +493,10 @@ class RoundMenu(QWidget):
self.isHideBySystem = True
e.accept()
def closeEvent(self, e):
e.accept()
self.closedSignal.emit()
def menuActions(self):
return self._actions
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册