本文整理汇总了Python中PyQt4.Qt.QPushButton.setSizePolicy方法的典型用法代码示例。如果您正苦于以下问题:Python QPushButton.setSizePolicy方法的具体用法?Python QPushButton.setSizePolicy怎么用?Python QPushButton.setSizePolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QPushButton
的用法示例。
在下文中一共展示了QPushButton.setSizePolicy方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: FontFamilyChooser
# 需要导入模块: from PyQt4.Qt import QPushButton [as 别名]
# 或者: from PyQt4.Qt.QPushButton import setSizePolicy [as 别名]
class FontFamilyChooser(QWidget):
family_changed = pyqtSignal(object)
def __init__(self, parent=None):
QWidget.__init__(self, parent)
self.l = l = QHBoxLayout()
l.setContentsMargins(0, 0, 0, 0)
self.setLayout(l)
self.button = QPushButton(self)
self.button.setIcon(QIcon(I('font.png')))
self.button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
l.addWidget(self.button)
self.default_text = _('Choose &font family')
self.font_family = None
self.button.clicked.connect(self.show_chooser)
self.clear_button = QToolButton(self)
self.clear_button.setIcon(QIcon(I('clear_left.png')))
self.clear_button.clicked.connect(self.clear_family)
l.addWidget(self.clear_button)
self.setToolTip = self.button.setToolTip
self.toolTip = self.button.toolTip
self.clear_button.setToolTip(_('Clear the font family'))
l.addStretch(1)
def clear_family(self):
self.font_family = None
@dynamic_property
def font_family(self):
def fget(self):
return self._current_family
def fset(self, val):
if not val:
val = None
self._current_family = val
self.button.setText(val or self.default_text)
self.family_changed.emit(val)
return property(fget=fget, fset=fset)
def show_chooser(self):
d = FontFamilyDialog(self.font_family, self)
if d.exec_() == d.Accepted:
self.font_family = d.font_family
示例2: setupWidgets
# 需要导入模块: from PyQt4.Qt import QPushButton [as 别名]
# 或者: from PyQt4.Qt.QPushButton import setSizePolicy [as 别名]
def setupWidgets(self):
self.setWindowTitle(self.title)
menubar = QMenuBar(self)
menu = QMenu("Title " + self.title)
self._action_tmp = QAction("Reproduce", self)
signal_connect(self._action_tmp, SIGNAL("activated()"), self.reproduce)
menu.addAction(self._action_tmp)
menubar.addMenu(menu)
menubar.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.setMenuBar(menubar)
cw = QWidget(self)
layout = QVBoxLayout(cw)
cw.setLayout(layout)
button = QPushButton("Reproduce", self)
button.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
layout.addWidget(button)
self.button = button
signal_connect(button, SIGNAL("clicked()"), self.reproduce)
for o in ("menubar", "menu", "cw"): setattr(self, o, eval(o))
self.setCentralWidget(cw)
示例3: AboutDialog
# 需要导入模块: from PyQt4.Qt import QPushButton [as 别名]
# 或者: from PyQt4.Qt.QPushButton import setSizePolicy [as 别名]
class AboutDialog(QDialog):
def __init__(self, parent=None, name=None, modal=0, fl=None):
if fl is None:
fl = Qt.Dialog | Qt.WindowTitleHint
QDialog.__init__(self, parent, Qt.Dialog | Qt.WindowTitleHint)
self.setModal(modal)
image0 = pixmaps.tigger_logo.pm()
# self.setSizeGripEnabled(0)
LayoutWidget = QWidget(self)
LayoutWidget.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
lo_top = QVBoxLayout(LayoutWidget)
lo_title = QHBoxLayout(None)
self.title_icon = QLabel(LayoutWidget)
self.title_icon.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.title_icon.setPixmap(image0)
self.title_icon.setAlignment(Qt.AlignCenter)
lo_title.addWidget(self.title_icon)
self.title_label = QLabel(LayoutWidget)
self.title_label.setWordWrap(True)
lo_title.addWidget(self.title_label)
lo_top.addLayout(lo_title)
lo_logos = QHBoxLayout(None)
lo_top.addLayout(lo_logos)
# for logo in ("astron",):
# icon = QLabel(LayoutWidget)
# icon.setSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed)
# icon.setPixmap(getattr(pixmaps,logo+"_logo").pm())
# icon.setAlignment(Qt.AlignCenter)
# lo_logos.addWidget(icon)
lo_mainbtn = QHBoxLayout(None)
lo_mainbtn.addItem(QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum))
lo_top.addLayout(lo_mainbtn)
self.btn_ok = QPushButton(LayoutWidget)
self.btn_ok.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
self.btn_ok.setMinimumSize(QSize(60, 0))
self.btn_ok.setAutoDefault(1)
self.btn_ok.setDefault(1)
lo_mainbtn.addWidget(self.btn_ok)
lo_mainbtn.addItem(QSpacerItem(20, 20, QSizePolicy.Expanding, QSizePolicy.Minimum))
self.languageChange()
LayoutWidget.adjustSize()
# LayoutWidget.resize(QSize(489,330).expandedTo(LayoutWidget.minimumSizeHint()))
# self.resize(QSize(489,330).expandedTo(self.minimumSizeHint()))
# self.clearWState(Qt.WState_Polished)
self.connect(self.btn_ok, SIGNAL("clicked()"), self.accept)
def languageChange(self):
self.setWindowTitle(self.__tr("About Tigger"))
self.title_label.setText(self.__tr( \
"""<h3>Tigger %s</h3>
<p>(C) 2010-2017 Oleg Smirnov & Rhodes University & SKA SA<br>
<br>Please direct feedback and bug reports at https://github.com/ska-sa/tigger</p>
""" % (release_string) \
))
self.btn_ok.setText(self.__tr("&OK"))
def __tr(self, s, c=None):
return qApp.translate("About", s, c)
示例4: __init__
# 需要导入模块: from PyQt4.Qt import QPushButton [as 别名]
# 或者: from PyQt4.Qt.QPushButton import setSizePolicy [as 别名]
class parameter_dialog_or_frame:
"""
use as a pre-mixin before QDialog or QFrame
"""
####@@@@
def __init__(self, parent = None, desc = None, name = None, modal = 0, fl = 0, env = None, type = "QDialog"):
if env is None:
import foundation.env as env # this is a little weird... probably it'll be ok, and logically it seems correct.
self.desc = desc
self.typ = type
if type == "QDialog":
QDialog.__init__(self,parent,name,modal,fl)
elif type == "QTextEdit":
QTextEdit.__init__(self, parent, name)
elif type == "QFrame":
QFrame.__init__(self,parent,name)
else:
print "don't know about type == %r" % (type,)
self.image1 = QPixmap()
self.image1.loadFromData(image1_data,"PNG") # should be: title_icon ####
self.image3 = QPixmap()
self.image3.loadFromData(image3_data,"PNG")
self.image4 = QPixmap()
self.image4.loadFromData(image4_data,"PNG")
self.image5 = QPixmap()
self.image5.loadFromData(image5_data,"PNG")
self.image6 = QPixmap()
self.image6.loadFromData(image6_data,"PNG")
self.image7 = QPixmap()
self.image7.loadFromData(image7_data,"PNG")
self.image0 = QPixmap(image0_data) # should be: border_icon ####
self.image2 = QPixmap(image2_data) # should be: sponsor_pixmap ####
try:
####@@@@
title_icon_name = self.desc.options.get('title_icon')
border_icon_name = self.desc.options.get('border_icon')
if title_icon_name:
self.image1 = imagename_to_pixmap(title_icon_name) ###@@@ pass icon_path
###@@@ import imagename_to_pixmap or use env function
# or let that func itself be an arg, or have an env arg for it
###e rename it icon_name_to_pixmap, or find_icon? (the latter only if it's ok if it returns an iconset)
###e use iconset instead?
if border_icon_name:
self.image0 = imagename_to_pixmap(border_icon_name)
except:
print_compact_traceback("bug in icon-setting code, using fallback icons: ")
pass
if not name:
self.setName("parameter_dialog_or_frame") ###
###k guess this will need: if type == 'QDialog'
self.setIcon(self.image0) # should be: border_icon ####
nanotube_dialogLayout = QVBoxLayout(self,0,0,"nanotube_dialogLayout")
self.heading_frame = QFrame(self,"heading_frame")
self.heading_frame.setPaletteBackgroundColor(QColor(122,122,122))
self.heading_frame.setFrameShape(QFrame.NoFrame)
self.heading_frame.setFrameShadow(QFrame.Plain)
heading_frameLayout = QHBoxLayout(self.heading_frame,0,3,"heading_frameLayout")
self.heading_pixmap = QLabel(self.heading_frame,"heading_pixmap")
self.heading_pixmap.setSizePolicy(QSizePolicy(QSizePolicy.Fixed,QSizePolicy.Fixed,0,0,self.heading_pixmap.sizePolicy().hasHeightForWidth()))
self.heading_pixmap.setPixmap(self.image1) # should be: title_icon ####
self.heading_pixmap.setScaledContents(1)
heading_frameLayout.addWidget(self.heading_pixmap)
self.heading_label = QLabel(self.heading_frame,"heading_label")
self.heading_label.setPaletteForegroundColor(QColor(255,255,255))
heading_label_font = QFont(self.heading_label.font())
heading_label_font.setPointSize(12)
heading_label_font.setBold(1)
self.heading_label.setFont(heading_label_font)
heading_frameLayout.addWidget(self.heading_label)
nanotube_dialogLayout.addWidget(self.heading_frame)
self.body_frame = QFrame(self,"body_frame")
self.body_frame.setFrameShape(QFrame.StyledPanel)
self.body_frame.setFrameShadow(QFrame.Raised)
body_frameLayout = QVBoxLayout(self.body_frame,3,3,"body_frameLayout")
self.sponsor_frame = QFrame(self.body_frame,"sponsor_frame")
self.sponsor_frame.setPaletteBackgroundColor(QColor(255,255,255))
self.sponsor_frame.setFrameShape(QFrame.StyledPanel)
self.sponsor_frame.setFrameShadow(QFrame.Raised)
sponsor_frameLayout = QHBoxLayout(self.sponsor_frame,0,0,"sponsor_frameLayout")
self.sponsor_btn = QPushButton(self.sponsor_frame,"sponsor_btn")
self.sponsor_btn.setAutoDefault(0) #bruce 060703 bugfix
self.sponsor_btn.setSizePolicy(QSizePolicy(QSizePolicy.Preferred,QSizePolicy.Preferred,0,0,self.sponsor_btn.sizePolicy().hasHeightForWidth()))
self.sponsor_btn.setPaletteBackgroundColor(QColor(255,255,255))
self.sponsor_btn.setPixmap(self.image2) # should be: sponsor_pixmap #### [also we'll need to support >1 sponsor]
self.sponsor_btn.setFlat(1)
sponsor_frameLayout.addWidget(self.sponsor_btn)
body_frameLayout.addWidget(self.sponsor_frame)
#.........这里部分代码省略.........
示例5: pb
# 需要导入模块: from PyQt4.Qt import QPushButton [as 别名]
# 或者: from PyQt4.Qt.QPushButton import setSizePolicy [as 别名]
def pb(text, tooltip=None):
b = QPushButton(text, self)
b.setToolTip(tooltip or '')
b.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
return b
示例6: LetsShareBooksDialog
# 需要导入模块: from PyQt4.Qt import QPushButton [as 别名]
# 或者: from PyQt4.Qt.QPushButton import setSizePolicy [as 别名]
class LetsShareBooksDialog(QDialog):
def __init__(self, gui, icon, do_user_config, qaction, us):
QDialog.__init__(self, gui)
self.gui = gui
self.do_user_config = do_user_config
self.qaction = qaction
self.us = us
self.clip = QApplication.clipboard()
self.main_gui = calibre_main()
self.urllib_thread = UrlLibThread(self.us)
self.kill_servers_thread = KillServersThread(self.us)
self.us.check_finished = True
self.pxmp = QPixmap()
self.pxmp.load('images/icon_connected.png')
self.icon_connected = QIcon(self.pxmp)
self.setStyleSheet("""
QDialog {
background-color: white;
}
QPushButton {
font-size: 16px;
border-style: solid;
border-color: red;
font-family:'BitstreamVeraSansMono',Consolas,monospace;
text-transform: uppercase;
}
QPushButton#arrow {
border-width: 16px;
border-right-color:white;
padding: -10px;
color:red;
}
QPushButton#url {
background-color: red;
min-width: 460px;
color: white;
text-align: left;
}
QPushButton#url:hover {
background-color: white;
color: red;
}
QPushButton#share {
background-color: red;
color: white;
margin-right: 10px;
}
QPushButton#share:hover {
background-color: white;
color: red;
}
QPushButton#url2 {
color: #222;
text-align: left;
}
QPushButton#url2:hover {
color: red;
}
""")
self.ll = QVBoxLayout()
#self.ll.setSpacing(1)
self.l = QHBoxLayout()
self.l.setSpacing(0)
self.l.setMargin(0)
#self.l.setContentsMargins(0,0,0,0)
self.w = QWidget()
self.w.setLayout(self.l)
self.setLayout(self.ll)
self.setWindowIcon(icon)
self.lets_share_button = QPushButton()
self.lets_share_button.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
self.lets_share_button.setObjectName("share")
self.lets_share_button.clicked.connect(self.lets_share)
self.stop_share_button = QPushButton()
self.stop_share_button.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
self.stop_share_button.setObjectName("share")
self.stop_share_button.clicked.connect(self.stop_share)
self.l.addWidget(self.lets_share_button)
self.l.addWidget(self.stop_share_button)
if self.us.button_state == "start":
self.lets_share_button.show()
self.stop_share_button.hide()
#.........这里部分代码省略.........
示例7: LetsShareBooksDialog
# 需要导入模块: from PyQt4.Qt import QPushButton [as 别名]
# 或者: from PyQt4.Qt.QPushButton import setSizePolicy [as 别名]
#.........这里部分代码省略.........
}
QLineEdit#edit {
background-color: white;
color: black;
font-size: 16px;
border-style: solid;
border-color: red;
font-family:'BitstreamVeraSansMono',Consolas,monospace;
text-transform: uppercase;
}
""")
self.ll = QVBoxLayout()
#self.ll.setSpacing(1)
self.l = QHBoxLayout()
self.l.setSpacing(0)
self.l.setMargin(0)
#self.l.setContentsMargins(0,0,0,0)
self.w = QWidget()
self.w.setLayout(self.l)
self.setLayout(self.ll)
self.setWindowIcon(icon)
self.debug_label = QLabel()
self.ll.addWidget(self.debug_label)
self.debug_label.show()
self.lets_share_button = QPushButton()
self.lets_share_button.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
self.lets_share_button.setObjectName("share")
#self.lets_share_button.clicked.connect(self.lets_share)
self.l.addWidget(self.lets_share_button)
self.url_label = QPushButton()
self.url_label.setSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
self.url_label.setObjectName("url")
#self.url_label.clicked.connect(self.open_url)
self.l.addWidget(self.url_label)
self.arrow_button = QPushButton("_____")
self.arrow_button.setObjectName("arrow")
self.l.addWidget(self.arrow_button)
self.ll.addWidget(self.w)
self.ll.addSpacing(5)
self.libranon_layout = QHBoxLayout()
self.libranon_layout.setSpacing(0)
self.libranon_layout.setMargin(0)
#self.l.setContentsMargins(0,0,0,0)
self.libranon_container = QWidget()
self.libranon_container.setLayout(self.libranon_layout)
self.edit = QLineEdit()
self.edit.setObjectName("edit")
self.edit.setSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
self.edit.setToolTip("Change your librarian name")
self.edit.setText(self.librarian)
#self.edit.textChanged.connect(self.handle_text_changed)
示例8: MainView
# 需要导入模块: from PyQt4.Qt import QPushButton [as 别名]
# 或者: from PyQt4.Qt.QPushButton import setSizePolicy [as 别名]
#.........这里部分代码省略.........
self.centralGridLayout.addWidget(self.voltageLabel, 2, 0, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.voltageString, 2, 1, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(hline2, 3, 0, 1, -1)
self.centralGridLayout.addWidget(self.currentLabel, 4, 0, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.currentString, 4, 1, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(hline3, 5, 0, 1, -1)
self.centralGridLayout.addWidget(self.frequencyLabel, 6, 0, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.frequencyString, 6, 1, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(hline4, 7, 0, 1, -1)
self.centralGridLayout.addWidget(vline1, 0, 2, -1, 1)
self.centralGridLayout.addWidget(self.activeEnergyLabel, 2, 3, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.activeEnergyString, 2, 4, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.apparentEnergyLabel, 4, 3, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.apparentEnergyString, 4, 4, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.reactiveEnergyLabel, 6, 3, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.reactiveEnergyString, 6, 4, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(vline2, 0, 5, -1, 1)
self.centralGridLayout.addWidget(self.activePowerLabel, 2, 6, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.activePowerString, 2, 7, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.apparentPowerLabel, 4, 6, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.apparentPowerString, 4, 7, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.reactivePowerLabel, 6, 6, 1, 1, QtCore.Qt.AlignLeft)
self.centralGridLayout.addWidget(self.reactivePowerString, 6, 7, 1, 1, QtCore.Qt.AlignLeft)
# self.centralGridLayout.addWidget(vline3, 0, 8, -1, 1)
# Buttons
self.startStopButton = QPushButton("START")
self.startStopButton.setFont(self.lcdStringFont)
buttonPolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
self.startStopButton.setSizePolicy(buttonPolicy)
self.startStopButton.clicked.connect(self.startStopClicked)
self.resetButton = QPushButton("RESET")
self.resetButton.setFont(self.lcdStringFont)
self.resetButton.setSizePolicy(buttonPolicy)
self.resetButton.clicked.connect(self.resetButtonClicked)
self.broadcastButton = QPushButton("BROADCAST")
self.broadcastButton.setFont(self.lcdStringFont)
self.broadcastButton.setSizePolicy(buttonPolicy)
self.broadcastButton.setCheckable(True)
self.broadcastButton.toggled.connect(self.broadcastButtonClicked)
self.centralGridLayout.addWidget(self.startStopButton, 8, 0, 1, 2)
self.centralGridLayout.addWidget(self.resetButton, 8, 3, 1, 2)
self.centralGridLayout.addWidget(self.broadcastButton, 8, 6, 1, 2)
# Status bar and show window
self.statusBar().showMessage('Ready')
self.setWindowTitle("ADE7753 Power Meter")
self.show()
# Button slots
def startStopClicked(self):
if(self._running):
self._running = False
self.startStopButton.setText("START")
self.startPressed.emit(False)
else:
self._running = True
self.startStopButton.setText("STOP")
self.startPressed.emit(True)
def resetButtonClicked(self):
self.resetPressed.emit()
def broadcastButtonClicked(self, s):
self.broadcastPressed.emit(s)
# Helper functions
def HLine(self):
line = QFrame()
line.setFrameStyle(QFrame.HLine)
line.setFrameShape(QFrame.HLine)
line.setFrameShadow(QFrame.Sunken)
return line
def VLine(self):
line = QFrame()
line.setFrameStyle(QFrame.VLine)
line.setFrameShape(QFrame.VLine)
line.setFrameShadow(QFrame.Sunken)
return line