当前位置: 首页>>代码示例>>Python>>正文


Python QTreeWidget.setMaximumWidth方法代码示例

本文整理汇总了Python中PyQt5.Qt.QTreeWidget.setMaximumWidth方法的典型用法代码示例。如果您正苦于以下问题:Python QTreeWidget.setMaximumWidth方法的具体用法?Python QTreeWidget.setMaximumWidth怎么用?Python QTreeWidget.setMaximumWidth使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PyQt5.Qt.QTreeWidget的用法示例。


在下文中一共展示了QTreeWidget.setMaximumWidth方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ServicesQWidget

# 需要导入模块: from PyQt5.Qt import QTreeWidget [as 别名]
# 或者: from PyQt5.Qt.QTreeWidget import setMaximumWidth [as 别名]

#.........这里部分代码省略.........
        """
        Update the QTreeWidget and its items

        :param services: list of :class:`Services <alignak_app.items.service.Service>` items
        :type services: list
        """

        self.services = services

        # Update services dashboard
        self.services_dashboard.update_widget(self.services)

        # Clear QTreeWidget
        self.services_tree_widget.clear()
        self.services_tree_widget.setIconSize(QSize(16, 16))

        if self.services:
            # Set as "Global" aggregation who are empty
            for service in self.services:
                if not service.data['aggregation']:
                    service.data['aggregation'] = 'Global'

            # First sort list by state then by aggregation
            newlist = sorted(
                self.services,
                key=lambda s: itemgetter('ls_state', 'ls_acknowledged', 'aggregation')(s.data)
            )
            self.services = newlist

            # Get list of aggregations
            aggregations = []
            for service in self.services:
                if service.data['aggregation'] not in aggregations:
                    aggregations.append(service.data['aggregation'])

            # Add QTreeWidgetItems
            for aggregation in aggregations:
                main_tree = QTreeWidgetItem()
                main_tree.setText(0, aggregation)
                main_tree.setIcon(0, QIcon(settings.get_image('tree')))
                main_tree.setToolTip(0, aggregation)
                for service in self.services:
                    if service.data['aggregation'] == aggregation:
                        service_tree = ServiceTreeItem()
                        service_tree.initialize(service)
                        service_tree.setToolTip(0, service.get_tooltip())
                        self.services_tree_widget.clicked.connect(self.update_service_data)
                        main_tree.addChild(service_tree)

                self.services_tree_widget.addTopLevelItem(main_tree)

            self.service_data_widget.hide()
        else:
            # If no services, reset service item to None and hide data widget
            self.service_data_widget.service_item = None
            self.service_data_widget.hide()

    def update_service_data(self):  # pragma: no cover
        """
        Update ServiceDataqWidget

        """

        service_item = self.sender().currentItem()

        if isinstance(service_item, (ServiceTreeItem, QListWidgetItem)):
            service = None
            # Get service
            if isinstance(service_item, ServiceTreeItem):
                service = data_manager.get_item('service', '_id', service_item.service_id)
            elif isinstance(service_item, QListWidgetItem):
                service = data_manager.get_item('service', '_id', service_item.data(Qt.UserRole))
            if not service:
                service = self.service_data_widget.service_item

            # Update QWidgets
            self.services_tree_widget.setMaximumWidth(self.width() * 0.5)
            self.services_list_widget.setMaximumWidth(self.width() * 0.5)
            self.service_data_widget.setMaximumWidth(self.width() * 0.5)
            self.service_data_widget.update_widget(service)
            self.services_dashboard.update_widget(self.services)
            self.service_data_widget.show()

            # Update Service Items (ServiceTreeItem, QListWidgetItem)
            if isinstance(service_item, ServiceTreeItem):
                service_item.update_item()
            else:
                monitored = \
                    service.data['passive_checks_enabled'] + service.data['active_checks_enabled']
                icon_name = get_icon_name(
                    'service',
                    service.data['ls_state'],
                    service.data['ls_acknowledged'],
                    service.data['ls_downtimed'],
                    monitored
                )

                service_item.setData(Qt.DecorationRole, QIcon(settings.get_image(icon_name)))
                service_item.setData(Qt.DisplayRole, service.get_display_name())
                service_item.setToolTip(service.get_tooltip())
开发者ID:Alignak-monitoring-contrib,项目名称:alignak-app,代码行数:104,代码来源:services.py


注:本文中的PyQt5.Qt.QTreeWidget.setMaximumWidth方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。