本文整理汇总了Python中PyQt4.Qt.QToolButton类的典型用法代码示例。如果您正苦于以下问题:Python QToolButton类的具体用法?Python QToolButton怎么用?Python QToolButton使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了QToolButton类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _init_controls
def _init_controls(self):
# Add the control set
vbl = QVBoxLayout()
self.move_rule_up_tb = QToolButton()
self.move_rule_up_tb.setObjectName("move_rule_up_tb")
self.move_rule_up_tb.setToolTip('Move rule up')
self.move_rule_up_tb.setIcon(QIcon(I('arrow-up.png')))
self.move_rule_up_tb.clicked.connect(self.move_row_up)
vbl.addWidget(self.move_rule_up_tb)
self.add_rule_tb = QToolButton()
self.add_rule_tb.setObjectName("add_rule_tb")
self.add_rule_tb.setToolTip('Add a new rule')
self.add_rule_tb.setIcon(QIcon(I('plus.png')))
self.add_rule_tb.clicked.connect(self.add_row)
vbl.addWidget(self.add_rule_tb)
self.delete_rule_tb = QToolButton()
self.delete_rule_tb.setObjectName("delete_rule_tb")
self.delete_rule_tb.setToolTip('Delete selected rule')
self.delete_rule_tb.setIcon(QIcon(I('list_remove.png')))
self.delete_rule_tb.clicked.connect(self.delete_row)
vbl.addWidget(self.delete_rule_tb)
self.move_rule_down_tb = QToolButton()
self.move_rule_down_tb.setObjectName("move_rule_down_tb")
self.move_rule_down_tb.setToolTip('Move rule down')
self.move_rule_down_tb.setIcon(QIcon(I('arrow-down.png')))
self.move_rule_down_tb.clicked.connect(self.move_row_down)
vbl.addWidget(self.move_rule_down_tb)
self.layout.addLayout(vbl)
示例2: _init_controls
def _init_controls(self):
# Add the control set
vbl = QVBoxLayout()
self.move_element_up_tb = QToolButton()
self.move_element_up_tb.setObjectName("move_element_up_tb")
self.move_element_up_tb.setToolTip('Move element up')
self.move_element_up_tb.setIcon(QIcon(I('arrow-up.png')))
self.move_element_up_tb.clicked.connect(self.move_row_up)
vbl.addWidget(self.move_element_up_tb)
self.undo_css_tb = QToolButton()
self.undo_css_tb.setObjectName("undo_css_tb")
self.undo_css_tb.setToolTip('Restore CSS to last saved')
self.undo_css_tb.setIcon(QIcon(I('edit-undo.png')))
self.undo_css_tb.clicked.connect(partial(self.undo_reset_button_clicked, 'undo'))
vbl.addWidget(self.undo_css_tb)
self.reset_css_tb = QToolButton()
self.reset_css_tb.setObjectName("reset_css_tb")
self.reset_css_tb.setToolTip('Reset CSS to default')
self.reset_css_tb.setIcon(QIcon(I('trash.png')))
self.reset_css_tb.clicked.connect(partial(self.undo_reset_button_clicked, 'reset'))
vbl.addWidget(self.reset_css_tb)
self.move_element_down_tb = QToolButton()
self.move_element_down_tb.setObjectName("move_element_down_tb")
self.move_element_down_tb.setToolTip('Move element down')
self.move_element_down_tb.setIcon(QIcon(I('arrow-down.png')))
self.move_element_down_tb.clicked.connect(self.move_row_down)
vbl.addWidget(self.move_element_down_tb)
self.layout.addLayout(vbl)
示例3: __init__
def __init__(self, parent, label, filename=None, dialog_label=None, file_types=None, default_suffix=None,
file_mode=QFileDialog.AnyFile):
QWidget.__init__(self, parent)
lo = QHBoxLayout(self)
lo.setContentsMargins(0, 0, 0, 0)
lo.setSpacing(5)
# label
lab = QLabel(label, self)
lo.addWidget(lab, 0)
# text field
self.wfname = QLineEdit(self)
self.wfname.setReadOnly(True)
self.setFilename(filename)
lo.addWidget(self.wfname, 1)
# selector
wsel = QToolButton(self)
wsel.setText("Choose...")
QObject.connect(wsel, SIGNAL("clicked()"), self._chooseFile)
lo.addWidget(wsel, 0)
# other init
self._file_dialog = None
self._dialog_label = dialog_label or label
self._file_types = file_types or "All files (*)"
self._file_mode = file_mode
self._default_suffix = default_suffix
self._dir = None
示例4: __init__
def __init__(self, parent, db, author, series=None):
QDialog.__init__(self, parent)
self.db = db
self.setWindowTitle(_('How many empty books?'))
self._layout = QGridLayout(self)
self.setLayout(self._layout)
self.qty_label = QLabel(_('How many empty books should be added?'))
self._layout.addWidget(self.qty_label, 0, 0, 1, 2)
self.qty_spinbox = QSpinBox(self)
self.qty_spinbox.setRange(1, 10000)
self.qty_spinbox.setValue(1)
self._layout.addWidget(self.qty_spinbox, 1, 0, 1, 2)
self.author_label = QLabel(_('Set the author of the new books to:'))
self._layout.addWidget(self.author_label, 2, 0, 1, 2)
self.authors_combo = EditWithComplete(self)
self.authors_combo.setSizeAdjustPolicy(
self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
self.authors_combo.setEditable(True)
self._layout.addWidget(self.authors_combo, 3, 0, 1, 1)
self.initialize_authors(db, author)
self.clear_button = QToolButton(self)
self.clear_button.setIcon(QIcon(I('trash.png')))
self.clear_button.setToolTip(_('Reset author to Unknown'))
self.clear_button.clicked.connect(self.reset_author)
self._layout.addWidget(self.clear_button, 3, 1, 1, 1)
self.series_label = QLabel(_('Set the series of the new books to:'))
self._layout.addWidget(self.series_label, 4, 0, 1, 2)
self.series_combo = EditWithComplete(self)
self.authors_combo.setSizeAdjustPolicy(
self.authors_combo.AdjustToMinimumContentsLengthWithIcon)
self.series_combo.setEditable(True)
self._layout.addWidget(self.series_combo, 5, 0, 1, 1)
self.initialize_series(db, series)
self.sclear_button = QToolButton(self)
self.sclear_button.setIcon(QIcon(I('trash.png')))
self.sclear_button.setToolTip(_('Reset series'))
self.sclear_button.clicked.connect(self.reset_series)
self._layout.addWidget(self.sclear_button, 5, 1, 1, 1)
self.create_epub = c = QCheckBox(_('Create an empty EPUB file as well'))
c.setChecked(gprefs.get('create_empty_epub_file', False))
c.setToolTip(_('Also create an empty EPUB file that you can subsequently edit'))
self._layout.addWidget(c, 6, 0, 1, -1)
button_box = self.bb = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
button_box.accepted.connect(self.accept)
button_box.rejected.connect(self.reject)
self._layout.addWidget(button_box, 7, 0, 1, -1)
self.resize(self.sizeHint())
示例5: SliderControl
class SliderControl(QObject):
"""This class implements a slider control for a colormap"""
def __init__(self, name, value, minval, maxval, step, format="%s: %.1f"):
QObject.__init__(self)
self.name, self.value, self.minval, self.maxval, self.step, self.format = \
name, value, minval, maxval, step, format
self._default = value
self._wlabel = None
def makeControlWidgets(self, parent, gridlayout, row, column):
toprow = QWidget(parent)
gridlayout.addWidget(toprow, row * 2, column)
top_lo = QHBoxLayout(toprow)
top_lo.setContentsMargins(0, 0, 0, 0)
self._wlabel = QLabel(self.format % (self.name, self.value), toprow)
top_lo.addWidget(self._wlabel)
self._wreset = QToolButton(toprow)
self._wreset.setText("reset")
self._wreset.setToolButtonStyle(Qt.ToolButtonTextOnly)
self._wreset.setAutoRaise(True)
self._wreset.setEnabled(self.value != self._default)
QObject.connect(self._wreset, SIGNAL("clicked()"), self._resetValue)
top_lo.addWidget(self._wreset)
self._wslider = QwtSlider(parent)
# This works around a stupid bug in QwtSliders -- see comments on histogram zoom wheel above
self._wslider_timer = QTimer(parent)
self._wslider_timer.setSingleShot(True)
self._wslider_timer.setInterval(500)
QObject.connect(self._wslider_timer, SIGNAL("timeout()"), self.setValue)
gridlayout.addWidget(self._wslider, row * 2 + 1, column)
self._wslider.setRange(self.minval, self.maxval)
self._wslider.setStep(self.step)
self._wslider.setValue(self.value)
self._wslider.setTracking(False)
QObject.connect(self._wslider, SIGNAL("valueChanged(double)"), self.setValue)
QObject.connect(self._wslider, SIGNAL("sliderMoved(double)"), self._previewValue)
def _resetValue(self):
self._wslider.setValue(self._default)
self.setValue(self._default)
def setValue(self, value=None, notify=True):
# only update widgets if already created
self.value = value
if self._wlabel is not None:
if value is None:
self.value = value = self._wslider.value()
self._wreset.setEnabled(value != self._default)
self._wlabel.setText(self.format % (self.name, self.value))
# stop timer if being called to finalize the change in value
if notify:
self._wslider_timer.stop()
self.emit(SIGNAL("valueChanged"), self.value)
def _previewValue(self, value):
self.setValue(notify=False)
self._wslider_timer.start(500)
self.emit(SIGNAL("valueMoved"), self.value)
示例6: __init__
def __init__(self, *args):
QToolButton.__init__(self, *args)
self.animation = QPropertyAnimation(self, 'iconSize', self)
self.animation.setDuration(60/72.*1000)
self.animation.setLoopCount(4)
self.normal_icon_size = QSize(64, 64)
self.animation.valueChanged.connect(self.value_changed)
self.setCursor(Qt.PointingHandCursor)
self.animation.finished.connect(self.animation_finished)
示例7: DateEdit
class DateEdit(QDateTimeEdit):
TOOLTIP = ''
LABEL = _('&Date:')
FMT = 'dd MMM yyyy hh:mm:ss'
ATTR = 'timestamp'
TWEAK = 'gui_timestamp_display_format'
def __init__(self, parent):
QDateTimeEdit.__init__(self, parent)
self.setToolTip(self.TOOLTIP)
self.setWhatsThis(self.TOOLTIP)
fmt = tweaks[self.TWEAK]
if fmt is None:
fmt = self.FMT
self.setDisplayFormat(fmt)
self.setCalendarPopup(True)
self.cw = CalendarWidget(self)
self.cw.setVerticalHeaderFormat(self.cw.NoVerticalHeader)
self.setCalendarWidget(self.cw)
self.setMinimumDateTime(UNDEFINED_QDATETIME)
self.setSpecialValueText(_('Undefined'))
self.clear_button = QToolButton(parent)
self.clear_button.setIcon(QIcon(I('trash.png')))
self.clear_button.setToolTip(_('Clear date'))
self.clear_button.clicked.connect(self.reset_date)
def reset_date(self, *args):
self.current_val = None
@dynamic_property
def current_val(self):
def fget(self):
return qt_to_dt(self.dateTime(), as_utc=False)
def fset(self, val):
if val is None:
val = UNDEFINED_DATE
else:
val = as_local_time(val)
self.setDateTime(val)
return property(fget=fget, fset=fset)
def initialize(self, db, id_):
self.current_val = getattr(db, self.ATTR)(id_, index_is_id=True)
self.original_val = self.current_val
def commit(self, db, id_):
if self.changed:
getattr(db, 'set_'+self.ATTR)(id_, self.current_val, commit=False,
notify=False)
return True
@property
def changed(self):
o, c = self.original_val, self.current_val
return o != c
示例8: create_color_button
def create_color_button(key, text):
b = ColorButton(data, key, text, self)
b.changed.connect(self.changed), l.addWidget(b)
bc = QToolButton(self)
bc.setIcon(QIcon(I('clear_left.png')))
bc.setToolTip(_('Remove color'))
bc.clicked.connect(b.clear)
h = QHBoxLayout()
h.addWidget(b), h.addWidget(bc)
return h
示例9: MovedDialog
class MovedDialog(QDialog): # {{{
def __init__(self, stats, location, parent=None):
QDialog.__init__(self, parent)
self.setWindowTitle(_("No library found"))
self._l = l = QGridLayout(self)
self.setLayout(l)
self.stats, self.location = stats, location
loc = self.oldloc = location.replace("/", os.sep)
self.header = QLabel(
_(
"No existing calibre library was found at %s. "
"If the library was moved, select its new location below. "
"Otherwise calibre will forget this library."
)
% loc
)
self.header.setWordWrap(True)
ncols = 2
l.addWidget(self.header, 0, 0, 1, ncols)
self.cl = QLabel("<br><b>" + _("New location of this library:"))
l.addWidget(self.cl, 1, 0, 1, ncols)
self.loc = QLineEdit(loc, self)
l.addWidget(self.loc, 2, 0, 1, 1)
self.cd = QToolButton(self)
self.cd.setIcon(QIcon(I("document_open.png")))
self.cd.clicked.connect(self.choose_dir)
l.addWidget(self.cd, 2, 1, 1, 1)
self.bb = QDialogButtonBox(QDialogButtonBox.Abort)
b = self.bb.addButton(_("Library moved"), self.bb.AcceptRole)
b.setIcon(QIcon(I("ok.png")))
b = self.bb.addButton(_("Forget library"), self.bb.RejectRole)
b.setIcon(QIcon(I("edit-clear.png")))
b.clicked.connect(self.forget_library)
self.bb.accepted.connect(self.accept)
self.bb.rejected.connect(self.reject)
l.addWidget(self.bb, 3, 0, 1, ncols)
self.resize(self.sizeHint() + QSize(100, 50))
def choose_dir(self):
d = choose_dir(self, "library moved choose new loc", _("New library location"), default_dir=self.oldloc)
if d is not None:
self.loc.setText(d)
def forget_library(self):
self.stats.remove(self.location)
def accept(self):
newloc = unicode(self.loc.text())
if not db_class.exists_at(newloc):
error_dialog(self, _("No library found"), _("No existing calibre library found at %s") % newloc, show=True)
return
self.stats.rename(self.location, newloc)
self.newloc = newloc
QDialog.accept(self)
示例10: MovedDialog
class MovedDialog(QDialog): # {{{
def __init__(self, stats, location, parent=None):
QDialog.__init__(self, parent)
self.setWindowTitle(_('No library found'))
self._l = l = QGridLayout(self)
self.setLayout(l)
self.stats, self.location = stats, location
loc = self.oldloc = location.replace('/', os.sep)
self.header = QLabel(_('No existing calibre library was found at %s. '
'If the library was moved, select its new location below. '
'Otherwise calibre will forget this library.')%loc)
self.header.setWordWrap(True)
ncols = 2
l.addWidget(self.header, 0, 0, 1, ncols)
self.cl = QLabel('<br><b>'+_('New location of this library:'))
l.addWidget(self.cl, 1, 0, 1, ncols)
self.loc = QLineEdit(loc, self)
l.addWidget(self.loc, 2, 0, 1, 1)
self.cd = QToolButton(self)
self.cd.setIcon(QIcon(I('document_open.png')))
self.cd.clicked.connect(self.choose_dir)
l.addWidget(self.cd, 2, 1, 1, 1)
self.bb = QDialogButtonBox(self)
b = self.bb.addButton(_('Library moved'), self.bb.AcceptRole)
b.setIcon(QIcon(I('ok.png')))
b = self.bb.addButton(_('Forget library'), self.bb.RejectRole)
b.setIcon(QIcon(I('edit-clear.png')))
self.bb.accepted.connect(self.accept)
self.bb.rejected.connect(self.reject)
l.addWidget(self.bb, 3, 0, 1, ncols)
self.resize(self.sizeHint() + QSize(100, 50))
def choose_dir(self):
d = choose_dir(self, 'library moved choose new loc',
_('New library location'), default_dir=self.oldloc)
if d is not None:
self.loc.setText(d)
def reject(self):
self.stats.remove(self.location)
QDialog.reject(self)
def accept(self):
newloc = unicode(self.loc.text())
if not LibraryDatabase2.exists_at(newloc):
error_dialog(self, _('No library found'),
_('No existing calibre library found at %s')%newloc,
show=True)
return
self.stats.rename(self.location, newloc)
self.newloc = newloc
QDialog.accept(self)
示例11: __init__
def __init__(self, current_family, parent=None):
QDialog.__init__(self, parent)
self.setWindowTitle(_('Choose font family'))
self.setWindowIcon(QIcon(I('font.png')))
from calibre.utils.fonts.scanner import font_scanner
self.font_scanner = font_scanner
self.m = QStringListModel(self)
self.build_font_list()
self.l = l = QGridLayout()
self.setLayout(l)
self.view = FontsView(self)
self.view.setModel(self.m)
self.view.setCurrentIndex(self.m.index(0))
if current_family:
for i, val in enumerate(self.families):
if icu_lower(val) == icu_lower(current_family):
self.view.setCurrentIndex(self.m.index(i))
break
self.view.doubleClicked.connect(self.accept, type=Qt.QueuedConnection)
self.view.changed.connect(self.current_changed,
type=Qt.QueuedConnection)
self.faces = Typefaces(self)
self.bb = QDialogButtonBox(QDialogButtonBox.Ok|QDialogButtonBox.Cancel)
self.bb.accepted.connect(self.accept)
self.bb.rejected.connect(self.reject)
self.add_fonts_button = afb = self.bb.addButton(_('Add &fonts'),
self.bb.ActionRole)
afb.setIcon(QIcon(I('plus.png')))
afb.clicked.connect(self.add_fonts)
self.ml = QLabel(_('Choose a font family from the list below:'))
self.search = QLineEdit(self)
self.search.setPlaceholderText(_('Search'))
self.search.returnPressed.connect(self.find)
self.nb = QToolButton(self)
self.nb.setIcon(QIcon(I('arrow-down.png')))
self.nb.setToolTip(_('Find Next'))
self.pb = QToolButton(self)
self.pb.setIcon(QIcon(I('arrow-up.png')))
self.pb.setToolTip(_('Find Previous'))
self.nb.clicked.connect(self.find_next)
self.pb.clicked.connect(self.find_previous)
l.addWidget(self.ml, 0, 0, 1, 4)
l.addWidget(self.search, 1, 0, 1, 1)
l.addWidget(self.nb, 1, 1, 1, 1)
l.addWidget(self.pb, 1, 2, 1, 1)
l.addWidget(self.view, 2, 0, 1, 3)
l.addWidget(self.faces, 1, 3, 2, 1)
l.addWidget(self.bb, 3, 0, 1, 4)
l.setAlignment(self.faces, Qt.AlignTop)
self.resize(800, 600)
示例12: __init__
def __init__(self, icon, text, splitter, parent=None, shortcut=None):
QToolButton.__init__(self, parent)
self.label = text
self.setIcon(QIcon(icon))
self.setCheckable(True)
self.splitter = splitter
splitter.state_changed.connect(self.update_state)
self.setCursor(Qt.PointingHandCursor)
self.shortcut = ''
if shortcut:
self.shortcut = shortcut
示例13: __init__
def __init__(self, parent, copy_fmt):
QWidget.__init__(self, parent)
self.dialog = parent
self.copy_fmt = copy_fmt
self.changed = False
self.l = l = QGridLayout()
self.setLayout(l)
self.cover_from_format_button = QToolButton(self)
self.cover_from_format_button.setToolTip(
_('Set the cover for the book from the selected format'))
self.cover_from_format_button.setIcon(QIcon(I('book.png')))
self.cover_from_format_button.setIconSize(QSize(32, 32))
self.metadata_from_format_button = QToolButton(self)
self.metadata_from_format_button.setIcon(QIcon(I('edit_input.png')))
self.metadata_from_format_button.setIconSize(QSize(32, 32))
self.metadata_from_format_button.setToolTip(
_('Set metadata for the book from the selected format'))
self.add_format_button = QToolButton(self)
self.add_format_button.setIcon(QIcon(I('add_book.png')))
self.add_format_button.setIconSize(QSize(32, 32))
self.add_format_button.clicked.connect(self.add_format)
self.add_format_button.setToolTip(
_('Add a format to this book'))
self.remove_format_button = QToolButton(self)
self.remove_format_button.setIcon(QIcon(I('trash.png')))
self.remove_format_button.setIconSize(QSize(32, 32))
self.remove_format_button.clicked.connect(self.remove_format)
self.remove_format_button.setToolTip(
_('Remove the selected format from this book'))
self.formats = FormatList(self)
self.formats.setAcceptDrops(True)
self.formats.formats_dropped.connect(self.formats_dropped)
self.formats.restore_fmt.connect(self.restore_fmt)
self.formats.delete_format.connect(self.remove_format)
self.formats.itemDoubleClicked.connect(self.show_format)
self.formats.setDragDropMode(self.formats.DropOnly)
self.formats.setIconSize(QSize(32, 32))
self.formats.setMaximumWidth(200)
l.addWidget(self.cover_from_format_button, 0, 0, 1, 1)
l.addWidget(self.metadata_from_format_button, 2, 0, 1, 1)
l.addWidget(self.add_format_button, 0, 2, 1, 1)
l.addWidget(self.remove_format_button, 2, 2, 1, 1)
l.addWidget(self.formats, 0, 1, 3, 1)
self.temp_files = []
示例14: MultipleWidget
class MultipleWidget(QWidget):
def __init__(self, parent):
QWidget.__init__(self, parent)
layout = QHBoxLayout()
layout.setSpacing(5)
layout.setContentsMargins(0, 0, 0, 0)
self.tags_box = EditWithComplete(parent)
layout.addWidget(self.tags_box, stretch=1000)
self.editor_button = QToolButton(self)
self.editor_button.setToolTip(_('Open Item Editor'))
self.editor_button.setIcon(QIcon(I('chapters.png')))
layout.addWidget(self.editor_button)
self.setLayout(layout)
def get_editor_button(self):
return self.editor_button
def update_items_cache(self, values):
self.tags_box.update_items_cache(values)
def clear(self):
self.tags_box.clear()
def setEditText(self):
self.tags_box.setEditText()
def addItem(self, itm):
self.tags_box.addItem(itm)
def set_separator(self, sep):
self.tags_box.set_separator(sep)
def set_add_separator(self, sep):
self.tags_box.set_add_separator(sep)
def set_space_before_sep(self, v):
self.tags_box.set_space_before_sep(v)
def setSizePolicy(self, v1, v2):
self.tags_box.setSizePolicy(v1, v2)
def setText(self, v):
self.tags_box.setText(v)
def text(self):
return self.tags_box.text()
示例15: makeControlWidgets
def makeControlWidgets(self, parent, gridlayout, row, column):
toprow = QWidget(parent)
gridlayout.addWidget(toprow, row * 2, column)
top_lo = QHBoxLayout(toprow)
top_lo.setContentsMargins(0, 0, 0, 0)
self._wlabel = QLabel(self.format % (self.name, self.value), toprow)
top_lo.addWidget(self._wlabel)
self._wreset = QToolButton(toprow)
self._wreset.setText("reset")
self._wreset.setToolButtonStyle(Qt.ToolButtonTextOnly)
self._wreset.setAutoRaise(True)
self._wreset.setEnabled(self.value != self._default)
QObject.connect(self._wreset, SIGNAL("clicked()"), self._resetValue)
top_lo.addWidget(self._wreset)
self._wslider = QwtSlider(parent)
# This works around a stupid bug in QwtSliders -- see comments on histogram zoom wheel above
self._wslider_timer = QTimer(parent)
self._wslider_timer.setSingleShot(True)
self._wslider_timer.setInterval(500)
QObject.connect(self._wslider_timer, SIGNAL("timeout()"), self.setValue)
gridlayout.addWidget(self._wslider, row * 2 + 1, column)
self._wslider.setRange(self.minval, self.maxval)
self._wslider.setStep(self.step)
self._wslider.setValue(self.value)
self._wslider.setTracking(False)
QObject.connect(self._wslider, SIGNAL("valueChanged(double)"), self.setValue)
QObject.connect(self._wslider, SIGNAL("sliderMoved(double)"), self._previewValue)