def contextEditMenu(self, menu, items=None): """ Called when the user would like to edit the item from the menu. The given menu is shown as a submenu of the main context menu. :type menu: QtWidgets.QMenu :type items: list[LibraryItem] :rtype: None """ if self.ENABLE_DELETE: action = QtWidgets.QAction("Delete", menu) action.triggered.connect(self.showDeleteDialog) menu.addAction(action) menu.addSeparator() action = QtWidgets.QAction("Rename", menu) action.triggered.connect(self.showRenameDialog) menu.addAction(action) action = QtWidgets.QAction("Move to", menu) action.triggered.connect(self.showMoveDialog) menu.addAction(action) action = QtWidgets.QAction("Show in Folder", menu) action.triggered.connect(self.showInFolder) menu.addAction(action)
def createItemSettingsMenu(self): menu = QtWidgets.QMenu('Item View', self) action = QtWidgets.QAction('Show labels', menu) action.setCheckable(True) action.setChecked(self.isItemTextVisible()) action.triggered[bool].connect(self.setItemTextVisible) menu.addAction(action) menu.addSeparator() action = studioqt.SliderAction('Size', menu) action.slider().setMinimum(10) action.slider().setMaximum(200) action.slider().setValue(self.zoomAmount()) action.slider().valueChanged.connect(self.setZoomAmount) menu.addAction(action) action = studioqt.SliderAction('Border', menu) action.slider().setMinimum(0) action.slider().setMaximum(20) action.slider().setValue(self.padding()) action.slider().valueChanged.connect(self.setPadding) menu.addAction(action) action = studioqt.SliderAction('Spacing', menu) action.slider().setMinimum(self.DEFAULT_MIN_SPACING) action.slider().setMaximum(self.DEFAULT_MAX_SPACING) action.slider().setValue(self.spacing()) action.slider().valueChanged.connect(self.setSpacing) menu.addAction(action) return menu
def __init__(self, *args, **kwargs): super(ButtonGroupFieldWidget, self).__init__(*args, **kwargs) self._value = "" self._buttons = {} items = self.data().get('items') widget = QtWidgets.QFrame() layout = QtWidgets.QHBoxLayout(widget) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) widget.setLayout(layout) i = 0 for item in items: i += 1 button = QtWidgets.QPushButton(toTitle(item), self) button.setCheckable(True) callback = functools.partial(self.setValue, item) button.clicked.connect(callback) self._buttons[item] = button if i == 1: button.setProperty('first', True) if i == len(items): button.setProperty('last', True) widget.layout().addWidget(button) self.setWidget(widget)
def reload(self): """ :rtype: None """ self.clear() if self._enableSelectContent: action = selectContentAction(item=self.item(), parent=self) self.addAction(action) self.addSeparator() selectionSets = self.selectionSets() if selectionSets: for selectionSet in selectionSets: dirname = os.path.basename(selectionSet.dirname()) basename = selectionSet.name().replace( selectionSet.extension(), "") nicename = dirname + ": " + basename action = QtWidgets.QAction(nicename, self) callback = partial(selectionSet.load, namespaces=self.namespaces()) action.triggered.connect(callback) self.addAction(action) else: action = QtWidgets.QAction("No selection sets found!", self) action.setEnabled(False) self.addAction(action)
def __init__(self, *args): QtWidgets.QFrame.__init__(self, *args) self.setObjectName("statusWidget") self.setFrameShape(QtWidgets.QFrame.NoFrame) self._blocking = False self._timer = QtCore.QTimer(self) self._label = QtWidgets.QLabel("", self) self._label.setCursor(QtCore.Qt.IBeamCursor) self._label.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) self._label.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred) self._button = QtWidgets.QPushButton(self) self._button.setMaximumSize(QtCore.QSize(17, 17)) self._button.setIconSize(QtCore.QSize(17, 17)) layout = QtWidgets.QHBoxLayout(self) layout.setContentsMargins(1, 0, 0, 0) layout.addWidget(self._button) layout.addWidget(self._label) self.setLayout(layout) self.setFixedHeight(19) self.setMinimumWidth(5) QtCore.QObject.connect(self._timer, QtCore.SIGNAL("timeout()"), self.reset)
def __init__(self, *args): QtWidgets.QFrame.__init__(self, *args) self.setObjectName("statusWidget") self.setFrameShape(QtWidgets.QFrame.NoFrame) self._label = QtWidgets.QLabel("Hello :)", self) policy = QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred self._label.setSizePolicy(*policy) self._timer = QtCore.QTimer(self) self._button = QtWidgets.QPushButton(self) self._button.setMaximumSize(QtCore.QSize(17, 17)) self._button.setIconSize(QtCore.QSize(17, 17)) layout = QtWidgets.QHBoxLayout(self) layout.setContentsMargins(1, 0, 0, 0) layout.addWidget(self._button) layout.addWidget(self._label) self.setLayout(layout) self.setFixedHeight(19) self.setMinimumWidth(5) QtCore.QObject.connect(self._timer, QtCore.SIGNAL("timeout()"), self.clear)
def __init__(self, *args, **kwargs): super(FormWidget, self).__init__(*args, **kwargs) self._schema = [] self._widgets = [] self._validator = None layout = QtWidgets.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.setLayout(layout) self._optionsFrame = QtWidgets.QFrame(self) self._optionsFrame.setObjectName("optionsFrame") layout = QtWidgets.QVBoxLayout(self._optionsFrame) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self._optionsFrame.setLayout(layout) self._titleWidget = QtWidgets.QPushButton(self) self._titleWidget.setCheckable(True) self._titleWidget.setObjectName("titleWidget") self._titleWidget.toggled.connect(self._titleClicked) self._titleWidget.hide() self.layout().addWidget(self._titleWidget) self.layout().addWidget(self._optionsFrame)
def createSpaceOperatorMenu(self, parent=None): """ Return the menu for changing the space operator. :type parent: QGui.QMenu :rtype: QGui.QMenu """ searchFilter = self.searchFilter() menu = QtWidgets.QMenu(parent) menu.setTitle('Space Operator') action = QtWidgets.QAction(menu) action.setText('OR') action.setCheckable(True) callback = partial(self.setSpaceOperator, searchFilter.Operator.OR) action.triggered.connect(callback) if searchFilter.spaceOperator() == searchFilter.Operator.OR: action.setChecked(True) menu.addAction(action) action = QtWidgets.QAction(menu) action.setText('AND') action.setCheckable(True) callback = partial(self.setSpaceOperator, searchFilter.Operator.AND) action.triggered.connect(callback) if searchFilter.spaceOperator() == searchFilter.Operator.AND: action.setChecked(True) menu.addAction(action) return menu
def __init__(self, title, widget, *args, **kwargs): super(GroupBoxWidget, self).__init__(*args, **kwargs) self._widget = None layout = QtWidgets.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.setLayout(layout) self._titleWidget = QtWidgets.QPushButton(self) self._titleWidget.setCheckable(True) self._titleWidget.setText(title) self._titleWidget.setObjectName("title") self._titleWidget.toggled.connect(self._toggle) self.layout().addWidget(self._titleWidget) self._widgetFrame = QtWidgets.QFrame(self) self._widgetFrame.setObjectName("frame") layout = QtWidgets.QVBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self._widgetFrame.setLayout(layout) self.layout().addWidget(self._widgetFrame) if widget: self.setWidget(widget)
def __init__(self, *args): QtWidgets.QToolButton.__init__(self, *args) self._imageSequence = ImageSequence("") self._imageSequence.frameChanged.connect(self._frameChanged) self._toolBar = QtWidgets.QToolBar(self) self._toolBar.setStyleSheet(STYLE) studioqt.fadeOut(self._toolBar, duration=0) spacer = QtWidgets.QWidget() spacer.setMaximumWidth(4) spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred) self._toolBar.addWidget(spacer) spacer = QtWidgets.QWidget() spacer.setMaximumWidth(4) spacer.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Preferred) self._firstSpacer = self._toolBar.addWidget(spacer) self.setSize(150, 150) self.setMouseTracking(True)
def createWidget(self, menu): """ This method is called by the QWidgetAction base class. :type menu: QtWidgets.QMenu """ widget = QtWidgets.QFrame(self.parent()) widget.setObjectName("filterByAction") facet = self._facet name = facet.get("name") or "" count = str(facet.get("count", 0)) title = name.replace(".", "").title() label = QtWidgets.QCheckBox(widget) label.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents) label.setText(title) label.installEventFilter(self) label.toggled.connect(self._triggered) label.setChecked(self._checked) label2 = QtWidgets.QLabel(widget) label2.setObjectName("actionCounter") label2.setText(count) layout = QtWidgets.QHBoxLayout(widget) layout.setSpacing(0) layout.setContentsMargins(0, 0, 0, 0) layout.addWidget(label, stretch=1) layout.addWidget(label2) widget.setLayout(layout) return widget
def createWidget(self, menu): """ This method is called by the QWidgetAction base class. :type menu: QtWidgets.QMenu """ widget = QtWidgets.QFrame(self.parent()) widget.setObjectName("filterByAction") title = self._name # Using a checkbox so that the text aligns with the other actions label = QtWidgets.QCheckBox(widget) label.setText(title) label.setAttribute(QtCore.Qt.WA_TransparentForMouseEvents) label.toggled.connect(self._triggered) label.setStyleSheet(""" #QCheckBox::indicator:checked { image: url(none.png) } QCheckBox::indicator:unchecked { image: url(none.png) } """) actionLayout = QtWidgets.QHBoxLayout(widget) actionLayout.setContentsMargins(0, 0, 0, 0) actionLayout.addWidget(label, stretch=1) widget.setLayout(actionLayout) return widget
def createWidget(self, parent): """ :type parent: QtWidgets.QMenu """ height = 25 spacing = 1 options = self.library().theme().options() styleSheet = studioqt.StyleSheet.fromText(LibraryAction.STYLE_SHEET, options=options) actionWidget = QtWidgets.QFrame(parent) actionWidget.setObjectName('actionWidget') actionWidget.setStyleSheet(styleSheet.data()) actionLabel = QtWidgets.QLabel(self.library().name(), actionWidget) actionLabel.setObjectName('actionLabel') actionLabel.setFixedHeight(height) iconColor = QtGui.QColor(255, 255, 255, 220) icon = studiolibrary.resource().icon('delete', color=iconColor) actionOption = QtWidgets.QPushButton('', actionWidget) actionOption.setObjectName('actionOption') actionOption.setIcon(icon) actionOption.setFixedHeight(height + spacing) actionOption.setFixedWidth(height) actionOption.clicked.connect(self.deleteLibrary) actionIcon = QtWidgets.QLabel('', actionWidget) actionIcon.setObjectName('actionIcon') actionIcon.setFixedWidth(10) actionIcon.setFixedHeight(height) actionLayout = QtWidgets.QHBoxLayout(actionWidget) actionLayout.setSpacing(0) actionLayout.setContentsMargins(0, 0, 0, 0) actionLayout.addWidget(actionIcon, stretch=1) actionLayout.addWidget(actionLabel, stretch=1) actionLayout.addWidget(actionOption, stretch=1) return actionWidget
def __init__(self, *args): QtWidgets.QWidget.__init__(self, *args) layout = QtWidgets.QHBoxLayout(self) self.setLayout(layout) layout.setContentsMargins(0,0,0,0) layout.setSpacing(0) self._dataset = None self._iconPadding = 6 self._iconButton = QtWidgets.QPushButton(self) self._iconButton.clicked.connect(self._onClicked) layout.addWidget(self._iconButton) icon = studiolibrary.resource().icon("pokeball") self._iconButton.setIcon(icon) self._comboBox = QtWidgets.QComboBox(self) layout.addWidget(self._comboBox, 1) self._comboBox.addItem("Select a character", "") self._comboBox.installEventFilter(self) self._comboBox.activated.connect(self._onActivated) self._comboBox.setSizePolicy( QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) self.setSizePolicy( QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum) self.update()
def __init__(self, parent=None, data=None, formWidget=None): super(FieldWidget, self).__init__(parent) self._data = data or {} self._error = False self._widget = None self._default = None self._required = None self._collapsed = False self._errorLabel = None self._menuButton = None self._actionResult = None self._formWidget = None if formWidget: self.setFormWidget(formWidget) self.setObjectName("fieldWidget") direction = self._data.get("layout", self.DefaultLayout) if direction == "vertical": layout = QtWidgets.QVBoxLayout(self) else: layout = QtWidgets.QHBoxLayout(self) layout.setContentsMargins(0, 0, 0, 0) layout.setSpacing(0) self.setContentsMargins(0, 0, 0, 0) self._label = QtWidgets.QLabel(self) self._label.setObjectName('label') self._label.setSizePolicy( QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred, ) layout.addWidget(self._label) self._layout2 = QtWidgets.QHBoxLayout(self) layout.addLayout(self._layout2) if direction == "vertical": self._label.setAlignment(QtCore.Qt.AlignLeft | QtCore.Qt.AlignVCenter) else: self._label.setAlignment(QtCore.Qt.AlignRight | QtCore.Qt.AlignVCenter) widget = self.createWidget() if widget: self.setWidget(widget)
def __init__(self, label='', parent=None, dpi=1): """ :type parent: QtWidgets.QMenu """ QtWidgets.QWidgetAction.__init__(self, parent) self.setObjectName('customAction') self._frame = QtWidgets.QFrame(parent) self._label = QtWidgets.QLabel(label, self._frame) self._label.setObjectName('sliderActionLabel') self._label.setMinimumWidth(85) self._slider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self._frame) self.valueChanged = self._slider.valueChanged
def __init__(self, path="", parent=None, startFrame=None, endFrame=None, step=1): """ :type path: str :type parent: QtWidgets.QWidget :type startFrame: int :type endFrame: int :type step: int """ parent = parent or mutils.gui.mayaWindow() QtWidgets.QDialog.__init__(self, parent) self._path = path self._step = step self._endFrame = None self._startFrame = None self._capturedPath = None if endFrame is None: endFrame = int(maya.cmds.currentTime(query=True)) if startFrame is None: startFrame = int(maya.cmds.currentTime(query=True)) self.setEndFrame(endFrame) self.setStartFrame(startFrame) self.setObjectName("CaptureWindow") self.setWindowTitle("Capture Window") self._captureButton = QtWidgets.QPushButton("Capture") self._captureButton.clicked.connect(self.capture) self._modelPanelWidget = mutils.gui.modelpanelwidget.ModelPanelWidget( self) vbox = QtWidgets.QVBoxLayout(self) vbox.setObjectName(self.objectName() + "Layout") vbox.addWidget(self._modelPanelWidget) vbox.addWidget(self._captureButton) self.setLayout(vbox) width = (self.DEFAULT_WIDTH * 1.5) height = (self.DEFAULT_HEIGHT * 1.5) + 50 self.setWidthHeight(width, height) self.centerWindow()
def __init__(self, libraries, parent=None): super(FolderLibraryCreateCustomWidget, self).__init__(parent) layout = QtWidgets.QHBoxLayout(self) self._label = QtWidgets.QLabel(libraries[0], self) layout.addWidget(self._label, 100) self._menu = studiolibrary.widgets.LibrarySelectMenu( libraries, 'to create', self) self._pushButton = QtWidgets.QPushButton("...", self) self._pushButton.clicked.connect(self._onclicked) layout.addWidget(self._pushButton, 1)
def createSettingsMenu(self): """ Create and return the settings menu for the widget. :rtype: QtWidgets.QMenu """ menu = QtWidgets.QMenu("Item View", self) menu.addSeparator() action = QtWidgets.QAction("Show labels", menu) action.setCheckable(True) action.setChecked(self.isItemTextVisible()) action.triggered[bool].connect(self.setItemTextVisible) menu.addAction(action) menu.addSeparator() sortByMenu = self.treeWidget().createSortByMenu() menu.addMenu(sortByMenu) groupByMenu = self.treeWidget().createGroupByMenu() menu.addMenu(groupByMenu) copyTextMenu = self.treeWidget().createCopyTextMenu() menu.addMenu(copyTextMenu) menu.addSeparator() action = studioqt.SliderAction("Size", menu) action.slider().setMinimum(10) action.slider().setMaximum(200) action.slider().setValue(self.zoomAmount()) action.slider().valueChanged.connect(self.setZoomAmount) menu.addAction(action) action = studioqt.SliderAction("Border", menu) action.slider().setMinimum(0) action.slider().setMaximum(20) action.slider().setValue(self.padding()) action.slider().valueChanged.connect(self.setPadding) menu.addAction(action) # action = studioqt.SliderAction("Spacing", menu) action.slider().setMinimum(self.DEFAULT_MIN_SPACING) action.slider().setMaximum(self.DEFAULT_MAX_SPACING) action.slider().setValue(self.spacing()) action.slider().valueChanged.connect(self.setSpacing) menu.addAction(action) return menu
def __init__(self, label="", parent=None): """ :type parent: QtWidgets.QMenu """ QtWidgets.QWidgetAction.__init__(self, parent) self._widget = SliderWidgetAction(parent) self._label = QtWidgets.QLabel(label, self._widget) self._slider = QtWidgets.QSlider(QtCore.Qt.Horizontal, self._widget) self._slider.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) self.valueChanged = self._slider.valueChanged
def __init__(self, parent=None): super(MessageBox, self).__init__(parent) self.setMinimumWidth(300) self.setMaximumWidth(400) self._standardButtonClicked = None self._header = QtWidgets.QFrame(self) self._header.setStyleSheet("background-color: rgb(50,150,200,0);") self._header.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Fixed) self._header.setFixedHeight(46) self._icon = QtWidgets.QLabel(self._header) self._icon.setAlignment(QtCore.Qt.AlignTop) self._icon.setScaledContents(True) self._icon.setFixedWidth(28) self._icon.setFixedHeight(28) self._icon.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) self._title = QtWidgets.QLabel(self._header) self._title.setStyleSheet("font: 14pt bold; color:rgb(255,255,255);") self._title.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) hlayout = QtWidgets.QHBoxLayout(self._header) hlayout.setSpacing(10) hlayout.addWidget(self._icon) hlayout.addWidget(self._title) self._header.setLayout(hlayout) self._message = QtWidgets.QLabel() self._message.setMinimumHeight(50) self._message.setWordWrap(True) self._message.setAlignment(QtCore.Qt.AlignLeft) self._message.setTextInteractionFlags(QtCore.Qt.TextSelectableByMouse) self._message.setSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Expanding) options = QtWidgets.QDialogButtonBox.Ok | QtWidgets.QDialogButtonBox.Cancel self._buttonBox = QtWidgets.QDialogButtonBox(None, QtCore.Qt.Horizontal, self) self._buttonBox.clicked.connect(self._clicked) self._buttonBox.accepted.connect(self.accept) self._buttonBox.rejected.connect(self.reject) vlayout1 = QtWidgets.QVBoxLayout(self) vlayout1.setContentsMargins(0, 0, 0, 0) vlayout1.addWidget(self._header) vlayout2 = QtWidgets.QVBoxLayout(self) vlayout2.setSpacing(25) vlayout2.setContentsMargins(15, 5, 15, 5) vlayout2.addWidget(self._message) vlayout2.addWidget(self._buttonBox) vlayout1.addLayout(vlayout2) self.setLayout(vlayout1)
def createWidget(self, menu): """ This method is called by the QWidgetAction base class. :type menu: QtWidgets.QMenu """ widget = QtWidgets.QFrame(self.parent()) widget.setObjectName("colorPickerAction") actionLayout = QtWidgets.QHBoxLayout(widget) actionLayout.setContentsMargins(0, 0, 0, 0) actionLayout.addWidget(self.picker(), stretch=1) widget.setLayout(actionLayout) return widget
def createActions(self): """ Crate the actions to be shown in the menu. :rtype: None """ # Create the menu actions for setting the accent color action = SeparatorAction("Accent", self) self.addAction(action) themes = self._themes if not themes: themes = themePresets() for theme in themes: if theme.accentColor(): action = ThemeAction(theme, self) self.addAction(action) if self.ENABLE_CUSTOM_ACTION: action = QtWidgets.QAction("Custom", self) action.triggered.connect(self.theme().browseAccentColor) color = self.theme().accentColor().toString() icon = studiolibrary.resource().icon(ThemesMenu.THEME_ICON, color=color) action.setIcon(icon) self.addAction(action) # Create the menu actions for setting the background color action = SeparatorAction("Background", self) self.addAction(action) for theme in themes: if not theme.accentColor() and theme.backgroundColor(): action = ThemeAction(theme, self) self.addAction(action) if self.ENABLE_CUSTOM_ACTION: action = QtWidgets.QAction("Custom", self) action.triggered.connect(self._theme.browseBackgroundColor) color = self._theme.backgroundColor().toString() icon = studiolibrary.resource().icon(ThemesMenu.THEME_ICON, color=color) action.setIcon(icon) self.addAction(action) self.triggered.connect(self._triggered)
def setColors(self, colors): """ Set the colors for the color bar. :type colors: list[str] or list[studioqt.Color] """ self.deleteButtons() self.layout().addStretch() for color in colors: if not isinstance(color, str): color = studioqt.Color(color) color = color.toString() callback = partial(self._colorChanged, color) css = "background-color: " + color button = self.COLOR_BUTTON_CLASS(self) button.setObjectName('colorButton') button.setStyleSheet(css) button.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) button.clicked.connect(callback) self.layout().addWidget(button) button = QtWidgets.QPushButton("...", self) button.setObjectName('browseColorButton') button.setSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred) button.clicked.connect(self.browseColor) self.layout().addWidget(button) self.layout().addStretch()
def __init__(self, *args, **kwargs): super(EnumFieldWidget, self).__init__(*args, **kwargs) widget = QtWidgets.QComboBox(self) widget.currentIndexChanged.connect(self.emitValueChanged) self.setWidget(widget)
def showMenu(self): """Show the menu using the actions from the data.""" menu = QtWidgets.QMenu(self) actions = self.data().get("actions", []) for action in actions: name = action.get("name", "No name found") callback = action.get("callback") func = functools.partial(self.actionCallback, callback) action = menu.addAction(name) action.triggered.connect(func) point = QtGui.QCursor.pos() point.setX(point.x() + 3) point.setY(point.y() + 3) # Reset the action results self._actionResult = None menu.exec_(point) if self._actionResult is not None: self.setValue(self._actionResult)
def __init__(self, *args, **kwargs): super(BoolFieldWidget, self).__init__(*args, **kwargs) widget = QtWidgets.QCheckBox(self) widget.stateChanged.connect(self.emitValueChanged) self.setWidget(widget)
def createHideColumnMenu(self): """ Create the hide column menu. :rtype: QtWidgets.QMenu """ menu = QtWidgets.QMenu("Show/Hide Column", self) action = menu.addAction("Show All") action.triggered.connect(self.showAllColumns) action = menu.addAction("Hide All") action.triggered.connect(self.hideAllColumns) menu.addSeparator() for column in range(self.columnCount()): label = self.labelFromColumn(column) isHidden = self.isColumnHidden(column) action = menu.addAction(label) action.setCheckable(True) action.setChecked(not isHidden) callback = partial(self.setColumnHidden, column, not isHidden) action.triggered.connect(callback) return menu
def createHeaderMenu(self, column): """ Creates a new header menu. :rtype: QtWidgets.QMenu """ menu = QtWidgets.QMenu(self) label = self.labelFromColumn(column) action = menu.addAction("Hide '{0}'".format(label)) callback = partial(self.setColumnHidden, column, True) action.triggered.connect(callback) menu.addSeparator() action = menu.addAction('Sort Ascending') callback = partial(self.sortByColumn, column, QtCore.Qt.AscendingOrder, self._groupColumn, self._groupOrder) action.triggered.connect(callback) action = menu.addAction('Sort Descending') callback = partial(self.sortByColumn, column, QtCore.Qt.DescendingOrder, self._groupColumn, self._groupOrder) action.triggered.connect(callback) menu.addSeparator() action = menu.addAction('Resize to Contents') callback = partial(self.resizeColumnToContents, column) action.triggered.connect(callback) return menu
def browseBackgroundColor(self): """ :rtype: None """ color = self.backgroundColor() d = QtWidgets.QColorDialog(self) d.setCurrentColor(color) colors = [(0, 0, 0), (20, 20, 30), (0, 30, 60), (0, 60, 60), (0, 60, 30), (60, 0, 10), (60, 0, 40), (40, 15, 5)] index = -1 for colorR, colorG, colorB in colors: for i in range(0, 6): index += 1 try: standardColor = QtGui.QColor(colorR, colorG, colorB) d.setStandardColor(index, standardColor) except: standardColor = QtGui.QColor(colorR, colorG, colorB).rgba() d.setStandardColor(index, standardColor) colorR += 20 colorB += 20 colorG += 20 d.currentColorChanged.connect(self.setBackgroundColor) d.open(self, QtCore.SLOT('blankSlot()')) if d.exec_(): self.setBackgroundColor(d.selectedColor()) else: self.setBackgroundColor(color)