本文整理匯總了Python中PyQt5.QtWidgets.QLineEdit.adjustSize方法的典型用法代碼示例。如果您正苦於以下問題:Python QLineEdit.adjustSize方法的具體用法?Python QLineEdit.adjustSize怎麽用?Python QLineEdit.adjustSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtWidgets.QLineEdit
的用法示例。
在下文中一共展示了QLineEdit.adjustSize方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: EditBox
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import adjustSize [as 別名]
class EditBox(QWidget):
""" Generate a simple box for editing
"""
def __init__(self, initv, lbl, format, parent=None):
"""
Parameters
----------
initv : str
Initial value
lbl : str
format : str
Format for text
"""
super(EditBox, self).__init__(parent)
self.value = initv
#
label = QLabel(lbl)
self.box = QLineEdit()
# Format
self.box.frmt = format
self.box.setText(self.box.frmt.format(self.value))
self.box.setMinimumWidth(90)
# Connect
self.box.textChanged[str].connect(self.setv)
#self.connect(self.box,
# QtCore.SIGNAL('editingFinished ()'), self.setv)
# Layout
vbox = QVBoxLayout()
vbox.addWidget(label)
vbox.addWidget(self.box)
self.setLayout(vbox)
def setv(self, text):
self.box.setText(text)
self.box.adjustSize()
self.value = str(self.box.text())
def set_text(self,value):
self.value = value
self.box.setText(self.box.frmt.format(self.value))
示例2: AnsBox
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import adjustSize [as 別名]
class AnsBox(QDialog):
"""Solicit an input answer from the User
"""
def __init__(self, lbl, format=str, parent=None):
"""
Parameters
----------
lbl : str
format : str
Format for value
"""
super(AnsBox, self).__init__(parent)
self.format=format
#
label = QLabel(lbl)
self.box = QLineEdit()
self.box.setMinimumWidth(90)
# Connect
self.box.textChanged[str].connect(self.setv)
self.box.editingFinished.connect(self.finish)
# Layout
vbox = QVBoxLayout()
vbox.addWidget(label)
vbox.addWidget(self.box)
self.setLayout(vbox)
def setv(self, text):
self.box.setText(text)
self.box.adjustSize()
def finish(self):
try:
self.value = self.format(ustr(self.box.text()))
except ValueError:
print('Bad input value! Try again with right type')
else:
self.done(0)
示例3: XAbsSysGui
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import adjustSize [as 別名]
#.........這裏部分代碼省略.........
vbox.addWidget(self.out_box)
# Write/Quit buttons
hbox1 = QHBoxLayout()
hbox1.addWidget(wqbtn)
hbox1.addWidget(qbtn)
buttons.setLayout(hbox1)
#
vbox.addWidget(buttons)
lines_widg.setLayout(vbox)
hbox = QHBoxLayout()
hbox.addWidget(self.vplt_widg)
hbox.addWidget(lines_widg)
self.setLayout(hbox)
# Initial draw
self.vplt_widg.on_draw()
# Overload, as needed
def on_key(self, event):
pass
# Change list of lines to choose from
def on_llist_change(self):
llist = self.pltline_widg.llist
all_lines = list( llist[llist['List']]._data['wrest'] )
# Set selected
wrest = [line.wrest for line in self.vplt_widg.abs_lines]
select = []
for iwrest in wrest:
try:
select.append(all_lines.index(iwrest))
except ValueError:
pass
select.sort()
# GUIs
self.vplt_widg.llist['List'] = llist['List']
self.vplt_widg.llist['show_line'] = select
self.vplt_widg.idx_line = 0
self.slines.selected = select
self.slines.on_list_change(llist[llist['List']])
# Write
def set_outfil(self, text):
self.out_box.setText(text)
self.out_box.adjustSize()
self.outfil = str(self.out_box.text())
print('AbsKin: Will write to {:s}'.format(self.outfil))
'''
# Set z from pltline_widg
def setz(self):
self.vplt_widg.z = self.pltline_widg.llist['z']
self.z = self.pltline_widg.llist['z']
self.vplt_widg.on_draw()
'''
def set_new_comps(self):
""" Generate new components and fill into abs_sys
Ignores velocity limits when building
"""
# Add spectrum filename, coord
abs_lines = self.vplt_widg.abs_lines
for line in abs_lines:
line.analy['datafile'] = self.vplt_widg.spec_fil
line.attrib['coord'] = self.abs_sys.coord
# Components
comps = ltiu.build_components_from_abslines(abs_lines, chk_vel=False)
self.abs_sys._components = comps
# Return
return
# Write
@pyqtSlot()
def write_out(self):
# Update components and spectrum filename
self.set_new_comps()
# Dict
adict = self.abs_sys.to_dict()
#QtCore.pyqtRemoveInputHook()
#xdb.set_trace()
#QtCore.pyqtRestoreInputHook()
print("Wrote abs_sys to {:s}".format(self.outfil))
with io.open(self.outfil, 'w', encoding='utf-8') as f:
f.write(json.dumps(adict, sort_keys=True, indent=4,
separators=(',', ': ')))
# Write + Quit
@pyqtSlot()
def write_quit(self):
self.write_out()
self.flg_quit = 1
self.done(1)
# Write + Quit
@pyqtSlot()
def quit(self):
self.flg_quit = 0
self.done(1)