本文整理汇总了Python中PyQt5.Qt.QListWidget.row方法的典型用法代码示例。如果您正苦于以下问题:Python QListWidget.row方法的具体用法?Python QListWidget.row怎么用?Python QListWidget.row使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.Qt.QListWidget
的用法示例。
在下文中一共展示了QListWidget.row方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: EventsQWidget
# 需要导入模块: from PyQt5.Qt import QListWidget [as 别名]
# 或者: from PyQt5.Qt.QListWidget import row [as 别名]
#.........这里部分代码省略.........
def send_datamanager_events(self):
"""
Add events stored in DataManager
"""
events = data_manager.get_events()
if events:
for event in events:
self.add_event(
event['event_type'],
event['message'],
timer=False,
host=event['host']
)
def add_event(self, event_type, msg, timer=False, host=None):
"""
Add event to events list
:param event_type: the type of event: OK, DOWN, ACK, ...
:type event_type: str
:param msg: message of event
:type msg: str
:param timer: timer to hide event at end of time
:type timer: bool
:param host: data of a host to set ``Qt.UserRole``
:type host: None | str
"""
if not self.event_exist(msg):
logger.debug(
'Add Event: msg: %s, timer: %s, host: %s', msg, timer, host
)
event = EventItem()
event.initialize(event_type, msg, timer=timer, host=host)
self.events_list.insertItem(0, event)
if timer:
event_duration = int(
settings.get_config('Alignak-app', 'notification_duration')
) * 1000
QTimer.singleShot(
event_duration,
lambda: self.remove_timer_event(event)
)
else:
logger.debug(
'Event with msg: %s already exist.', msg
)
def event_exist(self, msg):
"""
Check if event already displayed, move it to top and update tooltip.
Only for EventItem who have a ``Qt.UserRole``
:param msg: message of event
:type msg: str
:return: if message exist or not in events QWidgetList
:rtype: bool
"""
for i in range(0, self.events_list.count()):
if self.events_list.item(i).data(Qt.DisplayRole) == msg:
item = self.events_list.takeItem(i)
msg_to_send = '%s. (Send at %s)' % (msg, get_current_time())
item.setToolTip(msg_to_send)
self.events_list.insertItem(0, item)
return True
return False
def remove_timer_event(self, event):
"""
Remove EventItem with timer
:param event: EventItem with timer
:type event: EventItem
"""
logger.debug('Remove Timer Event: %s', event.text())
self.events_list.takeItem(self.events_list.row(event))
def remove_event(self, item=None):
"""
Remove item when user double click on an item
:param item: item to remove, else remove the current row
:type item: EventItem
"""
if isinstance(item, EventItem):
row = self.events_list.row(item)
self.events_list.takeItem(row)
else:
item = self.events_list.takeItem(self.events_list.currentRow())
logger.debug('Remove Event: %s', item.text())