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


Python QTreeWidget.setColumnCount方法代码示例

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


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

示例1: get_variable_table

# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnCount [as 别名]
    def get_variable_table(self, context):
        context_key = context.replace(' ', '-').lower()

        if context_key in self.variable_tables:
            table = self.variable_tables[context_key]
        else:
            table = QTreeWidget()
            table.setColumnCount(3)
            table.setHeaderLabels(['Name', 'Type', 'Value'])
            table.setColumnWidth(0, 250)
            table.setColumnWidth(1, 150)

            self.variable_tables[context_key] = table

            if context == 'Locals':
                self.insertTab(0, table, context)
            else:
                self.addTab(table, context)

            table.itemDoubleClicked.connect(
                self.handle_variable_double_clicked
            )

            self.setCurrentIndex(0)

        return table
开发者ID:Hailong,项目名称:pugdebug,代码行数:28,代码来源:variables.py

示例2: fillTreeWidget

# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnCount [as 别名]
    def fillTreeWidget(self, widget : QTreeWidget, tree : Tree):
        def helper(t : Tree, parent):
            item = QTreeWidgetItem()
            item.setText(0, t.name)
            item.setIcon(0, QIcon('data/gfx/folder.png'))
            if type(parent) == QTreeWidget:
                parent.insertTopLevelItem(0, item)
            else:
                parent.addChild(item)
            for ch in t.children:
                helper(ch, item)

        widget.setColumnCount(1)
        helper(tree, widget)
开发者ID:dushko,项目名称:G-,代码行数:16,代码来源:mainwindow.py

示例3: createTree

# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnCount [as 别名]
    def createTree(self):
        tree = QTreeWidget()
        tree.setColumnCount(1)
        root = QTreeWidgetItem(tree)
        root.setText(0, 'root')

        child1 = QTreeWidgetItem(root)
        child1.setText(0, 'child1')
        child1.setText(1, 'name1')
        child2 = QTreeWidgetItem(root)
        child2.setText(0, 'child2')
        child2.setText(1, 'name2')
        child3 = QTreeWidgetItem(root)
        child3.setText(0, 'child3')
        child4 = QTreeWidgetItem(child3)
        child4.setText(0, 'child4')
        child4.setText(1, 'name4')
        tree.addTopLevelItem(root)
        return tree
开发者ID:dormouse,项目名称:test,代码行数:21,代码来源:treewidgettest.py

示例4: InfoDialog

# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnCount [as 别名]
class InfoDialog(QDialog):

    def __init__(self, parent, info, title):
        super().__init__(parent)

        self.setWindowTitle('Media Info - ' + title)
        self.setWindowModality(QtCore.Qt.ApplicationModal)
        self.setMinimumSize(500, 250)
        self.resize(500, 250)

        self.vLayout = QVBoxLayout(self)

        self.infoTree = QTreeWidget(self)
        self.infoTree.setColumnCount(2)
        self.infoTree.setHeaderLabels(['Scope', 'Value'])
        self.infoTree.setAlternatingRowColors(True)
        self.infoTree.setSelectionMode(QAbstractItemView.NoSelection)
        self.infoTree.setEditTriggers(QAbstractItemView.NoEditTriggers)
        self.vLayout.addWidget(self.infoTree)

        self.__generate_widgets(info)
        self.infoTree.setColumnWidth(0, 150)

        self.buttonBox = QDialogButtonBox(self)
        self.buttonBox.setStandardButtons(QDialogButtonBox.Close)
        self.vLayout.addWidget(self.buttonBox)

        self.buttonBox.rejected.connect(self.close)

    def __generate_widgets(self, info, parent=None):
        for key in sorted(info.keys()):
            if(isinstance(info[key], dict)):
                widget = QTreeWidgetItem([key])
                self.__generate_widgets(info[key], widget)
            else:
                widget = QTreeWidgetItem([key, info[key]])

            if(parent):
                parent.addChild(widget)
            else:
                self.infoTree.addTopLevelItem(widget)
开发者ID:tornel,项目名称:linux-show-player,代码行数:43,代码来源:media_info.py

示例5: SheetDockWidget

# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnCount [as 别名]
class SheetDockWidget(QDockWidget):
    def __init__(self):
        super().__init__("Sheets")

        # Create main widget for content and layout of Dockwidget
        self.mainWidget = QWidget()
        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        self.mainWidgetLayout = QGridLayout(self.mainWidget)
        self.mainWidgetLayout.setSizeConstraint(QGridLayout.SetDefaultConstraint)

        # - Create frame for button and entry
        self.newSheetWidget = QWidget(self.mainWidget)
        self.newSheetWidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        self.newSheetWidgetLayout = QFormLayout(self.newSheetWidget)
        self.newSheetWidgetLayout.setContentsMargins(0, 0, 0, 0)

        self.newSheetButton = QPushButton(self.newSheetWidget)
        self.newSheetButton.setText("Create")
        self.newSheetButton.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.newSheetWidgetLayout.setWidget(0, QFormLayout.LabelRole, self.newSheetButton)

        self.newSheetLineedit = QLineEdit(self.newSheetWidget)
        #self.newSheetLineedit.setEditable(True)
        self.newSheetLineedit.setToolTip("Enter name for new sheet")
        self.newSheetLineedit.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
        self.newSheetWidgetLayout.setWidget(0, QFormLayout.FieldRole, self.newSheetLineedit)

        self.mainWidgetLayout.addWidget(self.newSheetWidget, 0, 0, 1, 1)

        # - Add worker treeview to content
        self.sheetTree = QTreeWidget(self.mainWidget)
        self.sheetTree.setColumnCount(1)

        self.sheetTree.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.mainWidgetLayout.addWidget(self.sheetTree, 1, 0, 1, 1)

        # Set dockwidget content to main widget
        self.setWidget(self.mainWidget)
开发者ID:DrLuke,项目名称:gpnshader,代码行数:40,代码来源:dockwidgets.py

示例6: CustomWidget

# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnCount [as 别名]
class CustomWidget(QMainWindow):

    def __init__(self):
        """
        Constructor
        """
        QMainWindow.__init__(self)
        self.name = "Custom widget"
        self.central_widget = QWidget()
        self.setCentralWidget(self.central_widget)

        # TODO: This is ugly, improve it
        self.icon_path = JConfig().icons_path

        self._createLayout()

    def _createGui(self):
        """
        Subclasses must override this
        depending on the elements they want to add
        self._createOutputTree(),
        self._createOutputTable(),
        self._createOutputWindow() and add them to
        the corresponding layouts.
        """
        raise NotImplementedError

    def _createToolBar(self, name):
        """
        Subclasses need to define the
        specific Actions
        """
        self.toolbar = self.addToolBar(name)
        self.toolbar.setMovable(False)

    def _createLayout(self):
        """
        This creates the basic layout:
        Buttons & Outputs
        """

        # Layouts (This is a common disposition)
        main_layout = QVBoxLayout()
        self.button_layout = QHBoxLayout()
        output_layout = QVBoxLayout()

        # You will need to create your buttons
        # and add them to your layout like this:
        # self.button_layout.addWidget(button_1)

        # Output Layout Inner (QSplitter)
        # Add as many widgets as you please
        # They will be ordered vertically and
        # be resizable by the user
        # self.splitter.addWidget(self.table_label)
        # self.splitter.addWidget(...)
        self.splitter = QSplitter(QtCore.Qt.Vertical)

        # Nested layouts
        main_layout.addLayout(self.button_layout)
        output_layout.addWidget(self.splitter)
        main_layout.addLayout(output_layout)
        self.central_widget.setLayout(main_layout)

    def _createOutputWindow(self):
        """
        Some binary analysis commands will output to this.
        """

        self.output_label = QLabel('Output')

        self.output_window = QTextEdit()
        self.output_window.setFontPointSize(10)
        self.output_window.setReadOnly(True)
        # Save it for later use
        self.output_window.original_textcolor = self.output_window.textColor()

    def _createOutputTable(self):
        """
        A vanilla QTableWidget. Callbacks modify
        its properties, like number of columns, etc.
        """
        self.table_label = QLabel('Table Output')

        self.table = QTableWidget()
        self.table.setColumnCount(3)
        self.table.setColumnWidth(0, 100)
        self.table.setColumnWidth(1, 300)
        self.table.setColumnWidth(2, 300)

        self.table.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)

        # Connect signals to slots
        self.table.customContextMenuRequested.connect(self._tablePopup)
        self.table.horizontalHeader().sectionDoubleClicked.connect(
            self._tableHeaderDoubleClicked)
        self.table.cellDoubleClicked.connect(self._tableCellDoubleClicked)

    def _createOutputTree(self):
        """
#.........这里部分代码省略.........
开发者ID:carlosgprado,项目名称:JARVIS,代码行数:103,代码来源:CustomWidget.py

示例7: PugdebugExpressionViewer

# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnCount [as 别名]
class PugdebugExpressionViewer(QWidget):

    expression_added_signal = pyqtSignal(int, str)
    expression_changed_signal = pyqtSignal(int, str)

    def __init__(self):
        super(PugdebugExpressionViewer, self).__init__()

        # Action for adding a new expression
        self.add_action = QAction(QIcon.fromTheme('list-add'), "&Add", self)
        self.add_action.triggered.connect(self.handle_add_action)

        # Action for deleting selected expressions
        self.delete_action = QAction(
            QIcon.fromTheme('list-remove'),
            "&Delete", self
        )
        self.delete_action.setShortcut(QKeySequence("Del"))
        self.delete_action.triggered.connect(self.handle_delete_action)

        self.toolbar = QToolBar()
        self.toolbar.setIconSize(QSize(16, 16))
        self.toolbar.addAction(self.add_action)
        self.toolbar.addAction(self.delete_action)

        self.tree = QTreeWidget()
        self.tree.setColumnCount(3)
        self.tree.setHeaderLabels(['Expression', 'Type', 'Value'])
        self.tree.setSelectionMode(QAbstractItemView.ContiguousSelection)
        self.tree.setContextMenuPolicy(Qt.CustomContextMenu)
        self.tree.customContextMenuRequested.connect(self.show_context_menu)

        layout = QVBoxLayout()
        layout.addWidget(self.toolbar)
        layout.addWidget(self.tree)
        self.setLayout(layout)

        self.restore_state()

        self.tree.itemChanged.connect(self.handle_item_changed)

    def show_context_menu(self, point):
        # Create the context menu on the tree widget
        context_menu = QMenu(self)

        # Add action is always visible
        context_menu.addAction(self.add_action)

        # If clicked on an row, offer to delete it
        if self.tree.itemAt(point):
            context_menu.addAction(self.delete_action)

        point = self.tree.mapToGlobal(point)
        context_menu.popup(point)

    def add_expression(self, expression):
        item = QTreeWidgetItem([expression, '', ''])
        item.setFlags(
            Qt.ItemIsEnabled |
            Qt.ItemIsEditable |
            Qt.ItemIsSelectable
        )
        self.tree.addTopLevelItem(item)

        #  Emit the signal to evaluate the expression
        index = self.tree.indexOfTopLevelItem(item)
        self.expression_added_signal.emit(index, expression)

    def delete_selected(self):
        """Deletes currently selected items from the tree"""
        for item in self.tree.selectedItems():
            index = self.tree.indexOfTopLevelItem(item)
            self.delete_expression(item)
            self.select_next(index)

    def select_next(self, index):
        """Selects the next item after an item has been deleted"""
        prev_item = self.tree.topLevelItem(index - 1)
        next_item = self.tree.topLevelItem(index)

        if prev_item:
            prev_item.setSelected(True)
        elif next_item:
            next_item.setSelected(True)

    def clear_values(self):
        """Deletes values for all expressions"""
        count = self.tree.topLevelItemCount()
        for index in range(0, count):
            item = self.tree.topLevelItem(index)
            item.setData(1, Qt.DisplayRole, '')
            item.setData(2, Qt.DisplayRole, '')
            item.takeChildren()

    def delete_expression(self, item):
        """Deletes the given item from the tree"""
        index = self.tree.indexOfTopLevelItem(item)
        self.tree.takeTopLevelItem(index)

    def get_expressions(self):
#.........这里部分代码省略.........
开发者ID:Hailong,项目名称:pugdebug,代码行数:103,代码来源:expressions.py

示例8: ImperiumWidget

# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnCount [as 别名]
class ImperiumWidget(QWidget):
    def __init__(self, parent=None):
        super(ImperiumWidget, self).__init__(parent)
        # objects, sub-windows
        self._world = XNovaWorld_instance()
        self._layout = None
        self._layout_topbuttons = None
        self._tree = None
        self._btn_reload = None
        # initialization
        self.setup_ui()

    def setup_ui(self):
        self._layout = QVBoxLayout()
        self.setLayout(self._layout)
        # create layout for top line of buttons
        self._layout_topbuttons = QHBoxLayout()
        self._layout.addLayout(self._layout_topbuttons)
        # create reload button
        self._btn_reload = QPushButton(self.tr('Refresh imperium'), self)
        self._btn_reload.setIcon(QIcon(':i/reload.png'))
        self._btn_reload.clicked.connect(self.on_btn_refresh_imperium)
        self._layout_topbuttons.addWidget(self._btn_reload)
        # finalize top buttons layout
        self._layout_topbuttons.addStretch()
        # create tree
        self._tree = QTreeWidget(self)
        self._tree.setAnimated(False)
        self._tree.setExpandsOnDoubleClick(True)
        self._tree.setHeaderHidden(False)
        self._tree.setItemsExpandable(True)
        self._tree.setRootIsDecorated(True)
        self._tree.setSortingEnabled(False)
        self._tree.setColumnCount(1)
        self._tree.setHeaderLabels(['None'])
        self._layout.addWidget(self._tree)
        self._tree.show()

    # called once after full world load
    def update_planets(self):
        def additem_helper(item_texts, twi_parent=None, align_flag=0):
            # align_flag = Qt::AlignLeft / Qt::AlignRight / Qt::AlignHCenter
            if align_flag == 0:
                align_flag = Qt.AlignHCenter | Qt.AlignVCenter
            twi = QTreeWidgetItem(item_texts)
            for it_col in range(len(item_texts)):
                if it_col > 0:
                    # void QTreeWidgetItem::setTextAlignment(int column, int alignment)
                    twi.setTextAlignment(it_col, align_flag)
            if twi_parent is None:
                self._tree.addTopLevelItem(twi)
            else:
                twi_parent.addChild(twi)
            return True

        self._tree.clear()  # clear the tree first
        planets = self._world.get_planets()  # get planets from the world
        #
        # setup header and its labels
        header_labels = ['-']
        for i in range(len(planets)):
            header_labels.append(planets[i].name)
        header_labels.append(self.tr('Total'))  # last column - totals
        self._tree.setHeaderLabels(header_labels)
        # alignment of text in header labels
        self._tree.header().setDefaultAlignment(Qt.AlignHCenter | Qt.AlignVCenter)
        # default column widths
        for i in range(len(planets)):
            if i < 1:
                self._tree.setColumnWidth(i, 150)
            else:
                self._tree.setColumnWidth(i, 75)
        #
        # planets names
        item_strings = [self.tr('Name')]
        for pl in planets:
            item_strings.append(pl.name)
        additem_helper(item_strings)
        #
        # planets coords
        item_strings = [self.tr('Coords')]
        for pl in planets:
            item_strings.append('[{0}:{1}:{2}]'.format(pl.coords.galaxy, pl.coords.system, pl.coords.position))
        additem_helper(item_strings)
        #
        # planets fields
        item_strings = [self.tr('Fields')]
        total_busy = 0
        total_fields = 0
        for pl in planets:
            total_busy += pl.fields_busy
            total_fields = pl.fields_total
            item_strings.append('{0} / {1}'.format(pl.fields_busy, pl.fields_total))
        item_strings.append('{0} / {1}'.format(total_busy, total_fields))
        additem_helper(item_strings)
        #
        # resources
        res_root = QTreeWidgetItem([self.tr('Resources')])
        item_strings = [self.tr('Metal')]
        total_res = 0
#.........这里部分代码省略.........
开发者ID:minlexx,项目名称:xnovacmd,代码行数:103,代码来源:imperium_widget.py

示例9: TorrentPreferencesDialog

# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnCount [as 别名]
class TorrentPreferencesDialog(QDialog):
    dataReady = pyqtSignal(dict)

    def __init__(self, parent, torrent_info):
        super().__init__(parent)
        self.torrentInfo = torrent_info

        self.setUp()

    def setUp(self):
        self.setWindowTitle("Torrent settings")

        parentRect = self.parentWidget().geometry()
        self.resize(parentRect.width() * 0.75, parentRect.height() * 0.9)
        self.setMinimumSize(self.size())

        # Create the dialog layout
        self.layout = QVBoxLayout(self)

        # Set up the destination folder selector
        self.setUpDialogHeader()
        # Set up the file lister for the torrent file
        self.setUpFileLister()
        # Set up the whole torrent priority combo box and buttons
        self.setUpDialogFooter()

    def setUpDialogHeader(self):
        headerLayout = QGridLayout()
        self.destinationFolder = paths.writableLocation(paths.DownloadLocation)
        torrentName = self.torrentInfo.name()

        # Show the torrent name row
        nameLabel = QLabel("Torrent name:", self)
        headerLayout.addWidget(nameLabel, 0, 0)

        nameEdit = QLineEdit(torrentName, self)
        nameEdit.setReadOnly(True)
        headerLayout.addWidget(nameEdit, 0, 1)

        # Show the destination folder row
        dirLabel = QLabel("Destination folder:", self)
        headerLayout.addWidget(dirLabel, 1, 0)

        self.textField = QLineEdit(self.destinationFolder, self)
        self.textField.setReadOnly(True)
        headerLayout.addWidget(self.textField, 1, 1)

        button = QPushButton("Browse", self)
        button.clicked.connect(self.selectFolder)
        headerLayout.addWidget(button, 1, 2)

        self.layout.addLayout(headerLayout)

    def selectFolder(self):
        newDir = str(QFileDialog.getExistingDirectory(self,
                                                      "Select Directory"))
        if newDir:
            self.textField.setText(newDir)
            self.destinationFolder = newDir

    def setUpFileLister(self):
        self.files = [(f.path, f.size) for f in self.torrentInfo.files()]
        self.treeView = QTreeWidget(self)
        self.treeView.setColumnCount(3)
        self.treeView.setColumnWidth(0, 350)
        self.treeView.setColumnWidth(1, 80)
        self.treeView.setHeaderLabels(["Name", "size", "Priority"])
        self.treeView.setExpandsOnDoubleClick(False)

        if len(self.files) == 1:
            tree = file_tree.FileTree(self.files[0][0], self.files[0][1])
        else:
            tree = file_tree.FileTree(self.files[0][0].split('/')[0], 0)
            for f in self.files:
                tree.add_file(f[0], f[1])

        rootItem = TreeNodeItem(tree.get_root(), self.treeView)
        self.treeView.addTopLevelItem(rootItem)
        self.treeView.expandAll()
        self.treeView.itemClicked.connect(self.rowClicked)
        self.layout.addWidget(self.treeView)

    def rowClicked(self, item, column):
        if item.checkState(0) == Qt.PartiallyChecked:
            item.setCheckState(0, Qt.Checked)

        if column == 2:
            priorityChanges = {'Normal': 'High',
                               'High': 'Low',
                               'Low': 'Normal',
                               'Mixed': 'Normal'}
            newPriority = priorityChanges[item.text(2)]
            self.changeTextOfAllChildren(item, 2, newPriority)

            self.reprioritize(item)

    def changeTextOfAllChildren(self, item, column, text):
        item.setText(column, text)
        for i in range(0, item.childCount()):
            self.changeTextOfAllChildren(item.child(i), column, text)
#.........这里部分代码省略.........
开发者ID:KOPURA,项目名称:GashoTorrent,代码行数:103,代码来源:torrent_settings_dialog.py

示例10: Shortcuts

# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnCount [as 别名]
class Shortcuts(preferences.Page):
    def __init__(self, dialog):
        super(Shortcuts, self).__init__(dialog)

        layout = QVBoxLayout()
        layout.setContentsMargins(0, 0, 0, 0)
        self.setLayout(layout)

        self.scheme = SchemeSelector(self)
        layout.addWidget(self.scheme)
        self.searchEntry = LineEdit()
        self.searchEntry.setPlaceholderText(_("Search..."))
        layout.addWidget(self.searchEntry)
        self.tree = QTreeWidget(self)
        self.tree.setHeaderLabels([_("Command"), _("Shortcut")])
        self.tree.setRootIsDecorated(False)
        self.tree.setColumnCount(2)
        self.tree.setAllColumnsShowFocus(True)
        self.tree.setAnimated(True)
        layout.addWidget(self.tree)

        self.edit = QPushButton(icons.get("preferences-desktop-keyboard-shortcuts"), '')
        layout.addWidget(self.edit)

        # signals
        self.searchEntry.textChanged.connect(self.updateFilter)
        self.scheme.currentChanged.connect(self.slotSchemeChanged)
        self.scheme.changed.connect(self.changed)
        self.tree.currentItemChanged.connect(self.slotCurrentItemChanged)
        self.tree.itemDoubleClicked.connect(self.editCurrentItem)
        self.edit.clicked.connect(self.editCurrentItem)

        # make a dict of all actions with the actions as key and the names as
        # value, with the collection prepended (for loading/saving)
        win = dialog.parent()
        allactions = {}
        for collection in actioncollectionmanager.manager(win).actionCollections():
            for name, action in collection.actions().items():
                allactions[action] = (collection, name)

        # keep a list of actions not in the menu structure
        left = list(allactions.keys())

        def add_actions(menuitem, actions):
            """Add actions to a QTreeWidgetItem."""
            for a in actions:
                if a.menu():
                    item = build_menu_item(a)
                    if item.childCount():
                        menuitem.addChild(item)
                elif a in left:
                    left.remove(a)
                    menuitem.addChild(ShortcutItem(a, *allactions[a]))
            menuitem.setFlags(Qt.ItemIsEnabled) # disable selection

        def build_menu_item(action):
            """Return a QTreeWidgetItem with children for all the actions in the submenu."""
            menuitem = QTreeWidgetItem()
            text = qutil.removeAccelerator(action.text())
            menuitem.setText(0, _("Menu {name}").format(name=text))
            add_actions(menuitem, action.menu().actions())
            return menuitem

        # present the actions nicely ordered as in the menus
        for a in win.menuBar().actions():
            menuitem = build_menu_item(a)
            if menuitem.childCount():
                self.tree.addTopLevelItem(menuitem)

        # sort leftover actions
        left.sort(key=lambda i: i.text())

        # show actions that are left, grouped by collection
        titlegroups = {}
        for a in left[:]: # copy
            collection, name = allactions[a]
            if collection.title():
                titlegroups.setdefault(collection.title(), []).append(a)
                left.remove(a)
        for title in sorted(titlegroups):
            item = QTreeWidgetItem(["{0}:".format(title)])
            for a in titlegroups[title]:
                item.addChild(ShortcutItem(a, *allactions[a]))
            self.tree.addTopLevelItem(item)
            item.setFlags(Qt.ItemIsEnabled) # disable selection

        # show other actions that were not in the menus
        item = QTreeWidgetItem([_("Other commands:")])
        for a in left:
            if a.text() and not a.menu():
                item.addChild(ShortcutItem(a, *allactions[a]))
        if item.childCount():
            self.tree.addTopLevelItem(item)
            item.setFlags(Qt.ItemIsEnabled) # disable selection

        self.tree.expandAll()

        item = self.tree.topLevelItem(0).child(0)
        if _lastaction:
            # find the previously selected item
#.........这里部分代码省略.........
开发者ID:19joho66,项目名称:frescobaldi,代码行数:103,代码来源:shortcuts.py

示例11: WorkerDockWidget

# 需要导入模块: from PyQt5.QtWidgets import QTreeWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QTreeWidget import setColumnCount [as 别名]
class WorkerDockWidget(QDockWidget):
    def __init__(self):
        super().__init__("Workers")

        # Create main widget for content and layout of Dockwidget
        self.mainWidget = QWidget()
        self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        self.mainWidgetLayout = QGridLayout(self.mainWidget)
        self.mainWidgetLayout.setSizeConstraint(QGridLayout.SetDefaultConstraint)

        # - Create frame for button and entry
        self.newConnWidget = QWidget(self.mainWidget)
        self.newConnWidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        self.newConnWidgetLayout = QFormLayout(self.newConnWidget)
        self.newConnWidgetLayout.setContentsMargins(0, 0, 0, 0)

        self.newConnButton = QPushButton(self.newConnWidget)
        self.newConnButton.setText("Connect")
        self.newConnButton.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.newConnWidgetLayout.setWidget(0, QFormLayout.LabelRole, self.newConnButton)

        self.newConnCombobox = QComboBox(self.newConnWidget)
        self.newConnCombobox.setEditable(True)
        self.newConnCombobox.setToolTip("Enter ip to connect to.\nEntry format:  ip:port\n(if port is omitted, default is used)")
        self.newConnCombobox.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
        self.newConnWidgetLayout.setWidget(0, QFormLayout.FieldRole, self.newConnCombobox)

        self.mainWidgetLayout.addWidget(self.newConnWidget, 0, 0, 1, 1)

        # - Add monitor controls
        self.controlsWidget = QWidget(self.mainWidget)
        self.controlsWidget.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
        self.controlsWidgetLayout = QGridLayout(self.controlsWidget)
        self.controlsWidgetLayout.setContentsMargins(0, 0, 0, 0)

        self.startRepeatButton = QPushButton(self.controlsWidget)
        self.startRepeatButton.setIcon(QIcon("resources/icons/control_play.png"))
        self.startRepeatButton.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.startRepeatButton.setEnabled(False)
        self.controlsWidgetLayout.addWidget(self.startRepeatButton, 0, 0, 1, 1)

        self.stopButton = QPushButton(self.controlsWidget)
        self.stopButton.setIcon(QIcon("resources/icons/control_stop.png"))
        self.stopButton.setSizePolicy(QSizePolicy.Minimum, QSizePolicy.Fixed)
        self.stopButton.setEnabled(False)
        self.controlsWidgetLayout.addWidget(self.stopButton, 0, 1, 1, 1)

        self.controlsSpacer = QSpacerItem(20, 40, QSizePolicy.Expanding, QSizePolicy.Fixed)
        self.controlsWidgetLayout.addItem(self.controlsSpacer, 0, 2, 1, 1)

        self.mainWidgetLayout.addWidget(self.controlsWidget, 1, 0, 1, 1)


        # - Add worker treeview to content
        self.workerTree = QTreeWidget(self.mainWidget)
        self.workerTree.setColumnCount(1)

        self.workerTree.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        self.mainWidgetLayout.addWidget(self.workerTree, 2, 0, 1, 1)

        # Set dockwidget content to main widget
        self.setWidget(self.mainWidget)
开发者ID:DrLuke,项目名称:gpnshader,代码行数:64,代码来源:dockwidgets.py


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