我们从Python开源项目中,提取了以下6个代码示例,用于说明如何使用PyQt5.QtCore.Qt.ToolButtonTextBesideIcon()。
def createButton(self, parent=None): button = QToolButton(parent) button.setCheckable(True) button.setSizePolicy(QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)) button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) button.setArrowType(Qt.DownArrow) button.setIconSize(QSize(3, 16)) ### #QIcon icon #icon.addPixmap(self.style().standardPixmap(QStyle.SP_ArrowDown), QIcon.Normal, QIcon.Off) #icon.addPixmap(self.style().standardPixmap(QStyle.SP_ArrowUp), QIcon.Normal, QIcon.On) #button.setIcon(icon) ### return button
def __init__(self, parent=None): super(VideoToolBar, self).__init__(parent) self.parent = parent self.setObjectName('appcontrols') self.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) self.setFloatable(False) self.setMovable(False) self.setIconSize(QSize(50, 53)) if sys.platform == 'darwin': self.setStyle(QStyleFactory.create('Fusion'))
def setLabelByType(self, label_type: str) -> None: if label_type == 'beside': self.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) [button.setText(button.text().replace(' ', '\n')) for button in self.findChildren(QToolButton)] elif label_type == 'under': self.setToolButtonStyle(Qt.ToolButtonTextUnderIcon) [button.setText(button.text().replace('\n', ' ')) for button in self.findChildren(QToolButton)] elif label_type == 'none': self.setToolButtonStyle(Qt.ToolButtonIconOnly) self.parent.settings.setValue('toolbarLabels', label_type)
def __init__(self,parent): QToolBar.__init__(self) #aaa=self.readStyleSheet(os.path.join(get_css_path(),"menu.css")) #aaa=str(aaa,'utf-8') #self.setStyleSheet(aaa) self.setToolButtonStyle( Qt.ToolButtonTextBesideIcon) self.setOrientation(Qt.Vertical) #self.setWindowFlags(Qt.FramelessWindowHint|Qt.WindowStaysOnTopHint|Qt.WindowStaysOnTopHint) self.setIconSize(QSize(42, 42)) self.configure_configwindow = QAction(QIcon_load("help"), _("Help window"), self) self.addAction(self.configure_configwindow) self.configure_configwindow = QAction(QIcon_load("help"), _("Manual"), self) self.addAction(self.configure_configwindow) self.configure_configwindow = QAction(QIcon_load("help"), _("License"), self) self.addAction(self.configure_configwindow) self.configure_configwindow = QAction(QIcon_load("help"), _("Youtube"), self) self.addAction(self.configure_configwindow) self.configure_configwindow = QAction(QIcon_load("help"), _("Citing the model"), self) self.addAction(self.configure_configwindow) self.configure_configwindow = QAction(QIcon_load("help"), _("About"), self) self.addAction(self.configure_configwindow) l=self.layout() for i in range(0,l.count()): l.itemAt(i).setAlignment(Qt.AlignLeft) self.installEventFilter(self) self.setWindowFlags(Qt.Popup) self.move(self.mapFromGlobal(QCursor.pos()))
def __init__(self, control_thread: 'ControlManagerThread'): super().__init__() self._control_thread = control_thread control = control_thread.control toolbar = self.addToolBar('Exits') toolbar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) toolbar.setMovable(False) self._add_action = toolbar.addAction(load_icon('add'), 'Add') self._add_action.triggered.connect(self._add_torrents_triggered) self._pause_action = toolbar.addAction(load_icon('pause'), 'Pause') self._pause_action.setEnabled(False) self._pause_action.triggered.connect(partial(self._control_action_triggered, control.pause)) self._resume_action = toolbar.addAction(load_icon('resume'), 'Resume') self._resume_action.setEnabled(False) self._resume_action.triggered.connect(partial(self._control_action_triggered, control.resume)) self._remove_action = toolbar.addAction(load_icon('remove'), 'Remove') self._remove_action.setEnabled(False) self._remove_action.triggered.connect(partial(self._control_action_triggered, control.remove)) self._about_action = toolbar.addAction(load_icon('about'), 'About') self._about_action.triggered.connect(self._show_about) self._list_widget = TorrentListWidget() self._list_widget.itemSelectionChanged.connect(self._update_control_action_state) self._list_widget.files_dropped.connect(self.add_torrent_files) self._torrent_to_item = {} # type: Dict[bytes, QListWidgetItem] self.setCentralWidget(self._list_widget) self.setMinimumSize(550, 450) self.resize(600, 500) self.setWindowTitle('BitTorrent Client') control_thread.error_happened.connect(self._error_happened) control.torrents_suggested.connect(self.add_torrent_files) control.torrent_added.connect(self._add_torrent_item) control.torrent_changed.connect(self._update_torrent_item) control.torrent_removed.connect(self._remove_torrent_item) self.show()
def __init__(self, parent=None, title='', animation_duration=300): """ References: # Adapted from c++ version http://stackoverflow.com/questions/32476006/how-to-make-an-expandable-collapsable-section-widget-in-qt """ super(GroupWidget, self).__init__(parent=parent) self.animation_duration = animation_duration self.toggle_animation = QParallelAnimationGroup() self.content_area = QScrollArea() self.header_line = QFrame() self.toggle_button = QToolButton() self.main_layout = QGridLayout() toggle_button = self.toggle_button toggle_button.setStyleSheet("QToolButton { border: none; }") toggle_button.setToolButtonStyle(Qt.ToolButtonTextBesideIcon) toggle_button.setArrowType(Qt.RightArrow) toggle_button.setText(str(title)) toggle_button.setCheckable(True) toggle_button.setChecked(False) header_line = self.header_line header_line.setFrameShape(QFrame.HLine) header_line.setFrameShadow(QFrame.Sunken) header_line.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Maximum) self.content_area.setStyleSheet("QScrollArea { background-color: white; border: none; }") self.content_area.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed) # start out collapsed self.content_area.setMaximumHeight(0) self.content_area.setMinimumHeight(0) # let the entire widget grow and shrink with its content toggle_animation = self.toggle_animation toggle_animation.addAnimation(QPropertyAnimation(self, bytes("minimumHeight", "utf-8"))) toggle_animation.addAnimation(QPropertyAnimation(self, bytes("maximumHeight", "utf-8"))) toggle_animation.addAnimation(QPropertyAnimation(self.content_area, bytes("maximumHeight", "utf-8"))) # don't waste space main_layout = self.main_layout main_layout.setVerticalSpacing(0) main_layout.setContentsMargins(0, 0, 0, 0) row = 0 main_layout.addWidget(self.toggle_button, row, 0, 1, 1, Qt.AlignLeft) main_layout.addWidget(self.header_line, row, 2, 1, 1) row += 1 main_layout.addWidget(self.content_area, row, 0, 1, 3) self.setLayout(self.main_layout) def start_animation(checked): arrow_type = Qt.DownArrow if checked else Qt.RightArrow direction = QAbstractAnimation.Forward if checked else QAbstractAnimation.Backward toggle_button.setArrowType(arrow_type) self.toggle_animation.setDirection(direction) self.toggle_animation.start() self.toggle_button.clicked.connect(start_animation)