def get_btn_rect(self, option): """Calculate the size and position of the checkbox.""" bsize = icons.get_iconsize('small') x = option.rect.x() + option.rect.width() / 2 - bsize.width() / 2 y = option.rect.y() + option.rect.height() / 2 - bsize.height() / 2 return QRect(QPoint(x, y), bsize)
def __init__(self, source_model, parent=None): super(BasicWatsonTableView, self).__init__(parent) self.setSortingEnabled(False) self.proxy_model = WatsonSortFilterProxyModel(source_model) self.setModel(self.proxy_model) # ---- Setup the delegates columns = source_model.COLUMNS self.setItemDelegateForColumn(columns['icons'], ToolButtonDelegate(self)) self.setItemDelegateForColumn(columns['project'], ComboBoxDelegate(self)) self.setItemDelegateForColumn(columns['comment'], LineEditDelegate(self)) self.setItemDelegateForColumn(columns['start'], DateTimeDelegate(self)) self.setItemDelegateForColumn(columns['end'], DateTimeDelegate(self)) self.setItemDelegateForColumn(columns['tags'], TagEditDelegate(self)) self.setItemDelegateForColumn(columns['duration'], BaseDelegate(self)) self.setItemDelegateForColumn(columns['id'], BaseDelegate(self)) # ---- Setup column size self.setColumnWidth(columns['tags'], 1.5 * self.horizontalHeader().defaultSectionSize()) self.setColumnWidth(columns['icons'], icons.get_iconsize('small').width() + 12) self.horizontalHeader().setSectionResizeMode(QHeaderView.Fixed) self.horizontalHeader().setSectionResizeMode(columns['comment'], QHeaderView.Stretch)
def __init__(self, icon=None, iconsize='normal', parent=None): super(QToolButtonBase, self).__init__(parent) self.setAutoRaise(True) self.setFocusPolicy(Qt.NoFocus) if icon is not None: self.setIcon( icons.get_icon(icon) if isinstance(icon, str) else icon) self.setIconSize( icons.get_iconsize(iconsize) if isinstance(iconsize, str ) else iconsize)
def paint(self, painter, option, index): """Paint a toolbutton with an icon.""" super(ToolButtonDelegate, self).paint(painter, option, index) opt = QStyleOptionToolButton() opt.rect = self.get_btn_rect(option) opt.iconSize = icons.get_iconsize('small') opt.state |= QStyle.State_Enabled | QStyle.State_Raised opt.icon = icons.get_icon('erase-right') QApplication.style().drawControl(QStyle.CE_ToolButtonLabel, opt, painter)
def setup_combobox(self): """ Setup the combobox where project can be selected, added, edited, and removed. """ project_cbox = ProjectView(self.model) project_cbox.setFixedHeight(icons.get_iconsize('small').height()) # Relay signals from the combobox. project_cbox.sig_rename_project.connect(self.sig_rename_project.emit) project_cbox.sig_add_project.connect(self.sig_add_project.emit) project_cbox.currentIndexChanged.connect(self.project_changed) return project_cbox
def setup_elapsed_timer(self): """Setup a digital clock to show the elpased time.""" self.elap_timer = ElapsedTimeLCDNumber() self.elap_timer.setToolTip( "<b>Elapsed Time</b><br><br>" "Time elapsed since the start of the activity currently" " being monitored.<br><br>" "The reference time used to calculate the elapsed time depends" " on the option selected in the \"Start from\" menu located in" " the bottom toolbar.") size_hint = self.elap_timer.sizeHint() size_ratio = size_hint.width() / size_hint.height() fix_height = self.buttons['start'].style().sizeFromContents( QStyle.CT_ToolButton, QStyleOptionToolButton(), icons.get_iconsize(self.__iconsize)).height() fix_width = fix_height * size_ratio self.elap_timer.setFixedSize(fix_width, fix_height) return self.elap_timer
def set_icon_size(self, icon_size): """Set the size of the button icon.""" self.btn_home.setIconSize(icons.get_iconsize(icon_size)) self.btn_prev.setIconSize(icons.get_iconsize(icon_size)) self.btn_next.setIconSize(icons.get_iconsize(icon_size))
# %% if __name__ == '__main__' if __name__ == '__main__': app = QApplication(sys.argv) drop_down_btn = DropDownToolButton(style=('text_beside')) drop_down_btn.setSizePolicy( QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred)) drop_down_btn.addItems( ['round to 1min', 'round to 5min', 'round to 10min']) onoff_button = OnOffToolButton('process_start', 'process_stop', 'normal') toolbar = ToolBarWidget() toolbar.addStretch(100) toolbar.addWidget(onoff_button) toolbar.addWidget(drop_down_btn) toolbar.addWidget(QToolButtonNormal('home')) toolbar.addWidget(None) toolbar.addWidget(HistoryNavigationWidget('tiny')) toolbar.show() size = toolbar.style().sizeFromContents(QStyle.CT_ToolButton, QStyleOptionToolButton(), icons.get_iconsize('normal')) print(size) sys.exit(app.exec_())