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


Python QVBoxLayout.update方法代码示例

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


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

示例1: TopicsTab

# 需要导入模块: from PyQt5.QtWidgets import QVBoxLayout [as 别名]
# 或者: from PyQt5.QtWidgets.QVBoxLayout import update [as 别名]
class TopicsTab(QWidget):
    configChanged = pyqtSignal()
    def __init__(self):
        super(QWidget, self).__init__()
        self.config = None
        self.count = 0
        self.topicRows = {}

        self.nameEdit = QLineEdit()
        self.dataTypeComboBox = QComboBox()
        self.fillDataTypes()
        self.opTypeComboBox = QComboBox()
        self.opTypeComboBox.addItem('sub', 'Subscribe')
        self.opTypeComboBox.addItem('pub', 'Publish')
        self.addButton = QPushButton('Add')
        self.addButton.clicked.connect(self.addClicked)

        self.mainLayout = QVBoxLayout()
        rowLayout = QHBoxLayout()
        rowLayout.addWidget(self.nameEdit)
        rowLayout.addWidget(self.dataTypeComboBox)
        rowLayout.addWidget(self.opTypeComboBox)
        rowLayout.addWidget(self.addButton)
        rowContainer = QWidget()
        rowContainer.setLayout(rowLayout)
        rowContainer.setObjectName('titleRow')
        self.mainLayout.addWidget(rowContainer)
        self.setLayout(self.mainLayout)


    def fillDataTypes(self):
        rosTypes = Interfaces.getRosMessageTypes()
        for type in rosTypes:
            concatType = type['typeDir'] + '/' + type['type']
            self.dataTypeComboBox.addItem(concatType, concatType)


    def addTopicRow(self, name, type, opType):
        rowLayout = QHBoxLayout()
        rowLayout.addWidget(QLabel(name))
        rowLayout.addWidget(QLabel(type))
        rowLayout.addWidget(QLabel(opType))
        removeButton = QPushButton('Remove')
        removeButton.clicked.connect(self.removeTopicClicked)
        removeButton.setObjectName(str(self.count))
        rowLayout.addWidget(removeButton)
        rowContainer = QWidget()
        rowContainer.setLayout(rowLayout)
        rowContainer.setObjectName('row' + str(self.count))
        self.mainLayout.addWidget(rowContainer)
        self.topicRows[self.count] = rowContainer
        self.count += 1


    def addClicked(self):
        if self.config is not None:
            self.config.addTopic(self.count, self.nameEdit.text(), self.dataTypeComboBox.currentData(), self.opTypeComboBox.currentData())
            self.addTopicRow(self.nameEdit.text(), self.dataTypeComboBox.currentData(), self.opTypeComboBox.currentData())
            self.nameEdit.setText('')
            self.configChanged.emit()

    def removeTopicClicked(self):
        if self.config is not None:
            itemToRemove = None
            for i in range(self.mainLayout.count()):
                if self.mainLayout.itemAt(i).widget().objectName() == 'row' + self.sender().objectName():
                    itemToRemove = self.mainLayout.itemAt(i)
                    break
            if itemToRemove is not None:
                self.mainLayout.removeItem(itemToRemove)
                itemToRemove.widget().setParent(None)
                self.mainLayout.update()
                self.configChanged.emit()
            self.config.removeTopic(int(self.sender().objectName()))
            del self.topicRows[int(self.sender().objectName())]


    def clearAllRows(self):
        clearList = []
        for i in range(self.mainLayout.count()):
            item = self.mainLayout.itemAt(i)
            if item.widget().objectName() != 'titleRow':
                clearList.append(item)

        for item in clearList:
            self.mainLayout.removeItem(item)
            item.widget().setParent(None)

        self.mainLayout.update()
        self.count = 0


    def setConfig(self, config):
        self.config = config
        self.clearAllRows()
        for topic in self.config.getTopics():
            topic['id'] = self.count
            self.addTopicRow(topic['name'], topic['type'], topic['opType'])
开发者ID:Diegojnb,项目名称:JdeRobot,代码行数:100,代码来源:rosconfigdialog.py


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