本文整理匯總了Python中PyQt5.QtWidgets.QLineEdit.setFocusPolicy方法的典型用法代碼示例。如果您正苦於以下問題:Python QLineEdit.setFocusPolicy方法的具體用法?Python QLineEdit.setFocusPolicy怎麽用?Python QLineEdit.setFocusPolicy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtWidgets.QLineEdit
的用法示例。
在下文中一共展示了QLineEdit.setFocusPolicy方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: createEditor
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setFocusPolicy [as 別名]
def createEditor(self, parent, option, index):
self.updateRects(option, index)
bgColor = self.bgColors.get(index, "white")
if self.mainLineRect.contains(self.lastPos):
# One line summary
self.editing = Outline.summarySentence
edt = QLineEdit(parent)
edt.setFocusPolicy(Qt.StrongFocus)
edt.setFrame(False)
f = QFont(option.font)
if self.newStyle():
f.setBold(True)
else:
f.setItalic(True)
edt.setAlignment(Qt.AlignCenter)
edt.setPlaceholderText(self.tr("One line summary"))
edt.setFont(f)
edt.setStyleSheet("background: {}; color: black;".format(bgColor))
return edt
elif self.titleRect.contains(self.lastPos):
# Title
self.editing = Outline.title
edt = QLineEdit(parent)
edt.setFocusPolicy(Qt.StrongFocus)
edt.setFrame(False)
f = QFont(option.font)
if self.newStyle():
f.setPointSize(f.pointSize() + 4)
else:
edt.setAlignment(Qt.AlignCenter)
f.setBold(True)
edt.setFont(f)
edt.setStyleSheet("background: {}; color: black;".format(bgColor))
# edt.setGeometry(self.titleRect)
return edt
else: # self.mainTextRect.contains(self.lastPos):
# Summary
self.editing = Outline.summaryFull
edt = QPlainTextEdit(parent)
edt.setFocusPolicy(Qt.StrongFocus)
edt.setFrameShape(QFrame.NoFrame)
try:
# QPlainTextEdit.setPlaceholderText was introduced in Qt 5.3
edt.setPlaceholderText(self.tr("Full summary"))
except AttributeError:
pass
edt.setStyleSheet("background: {}; color: black;".format(bgColor))
return edt
示例2: createEditor
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setFocusPolicy [as 別名]
def createEditor(self, parent, option, index):
self.updateRects(option, index)
if self.mainLineRect.contains(self.lastPos):
# One line summary
self.editing = Outline.summarySentence
edt = QLineEdit(parent)
edt.setFocusPolicy(Qt.StrongFocus)
edt.setFrame(False)
edt.setAlignment(Qt.AlignCenter)
edt.setPlaceholderText(self.tr("One line summary"))
f = QFont(option.font)
f.setItalic(True)
edt.setFont(f)
return edt
elif self.titleRect.contains(self.lastPos):
# Title
self.editing = Outline.title
edt = QLineEdit(parent)
edt.setFocusPolicy(Qt.StrongFocus)
edt.setFrame(False)
f = QFont(option.font)
# f.setPointSize(f.pointSize() + 1)
f.setBold(True)
edt.setFont(f)
edt.setAlignment(Qt.AlignCenter)
# edt.setGeometry(self.titleRect)
return edt
else: # self.mainTextRect.contains(self.lastPos):
# Summary
self.editing = Outline.summaryFull
edt = QPlainTextEdit(parent)
edt.setFocusPolicy(Qt.StrongFocus)
edt.setFrameShape(QFrame.NoFrame)
try:
# QPlainTextEdit.setPlaceholderText was introduced in Qt 5.3
edt.setPlaceholderText(self.tr("Full summary"))
except AttributeError:
pass
return edt
示例3: EditView
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setFocusPolicy [as 別名]
#.........這裏部分代碼省略.........
def get_cursor_val(self):
return (self.Editor.textCursor().position(), self.Editor.textCursor.anchor())
# Some other code likes to reposition the edit selection:
def set_cursor(self, tc):
self.Editor.setTextCursor(tc)
# Make a valid cursor based on position and anchor values possibly
# input by the user.
def make_cursor(self, position, anchor):
mx = self.document.characterCount()
tc = QTextCursor(self.Editor.textCursor())
anchor = min( max(0,anchor), mx )
position = min ( max(0,position), mx )
tc.setPosition(anchor)
tc.setPosition(position,QTextCursor.KeepAnchor)
return tc
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# INITIALIZE UI
#
# First we built the Edit panel using Qt Creator which produced a large
# and somewhat opaque block of code that had to be mixed in by
# multiple inheritance. This had several drawbacks, so the following
# is a "manual" UI setup using code drawn from the generated code.
#
def _uic(self):
# First set up the properties of "self", a QWidget.
self.setObjectName("EditViewWidget")
sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(1)
sizePolicy.setHeightForWidth(False) # don't care to bind height to width
self.setSizePolicy(sizePolicy)
self.setMinimumSize(QSize(250, 250))
self.setFocusPolicy(Qt.StrongFocus)
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.setWindowTitle("")
self.setToolTip("")
self.setStatusTip("")
self.setWhatsThis("")
# Set up our primary widget, the editor
self.Editor = PTEditor(self,self.my_book)
self.Editor.setObjectName("Editor")
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(2) # Edit deserves all available space
sizePolicy.setVerticalStretch(2)
sizePolicy.setHeightForWidth(False)
self.Editor.setSizePolicy(sizePolicy)
self.Editor.setFocusPolicy(Qt.StrongFocus)
self.Editor.setContextMenuPolicy(Qt.NoContextMenu)
self.Editor.setAcceptDrops(True)
self.Editor.setLineWidth(2)
self.Editor.setDocumentTitle("")
self.Editor.setLineWrapMode(QPlainTextEdit.NoWrap)
# Set up the frame that will contain the bottom row of widgets
# It doesn't need a parent and doesn't need to be a class member
# because it will be added to a layout, which parents it.
bot_frame = QFrame()
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(False)
bot_frame.setSizePolicy(sizePolicy)
bot_frame.setMinimumSize(QSize(0, 24))
bot_frame.setContextMenuPolicy(Qt.NoContextMenu)
bot_frame.setFrameShape(QFrame.Panel)
示例4: EditView
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setFocusPolicy [as 別名]
#.........這裏部分代碼省略.........
def get_cursor_val(self):
return (self.Editor.textCursor().position(), self.Editor.textCursor().anchor())
# Some other code likes to reposition the edit selection:
def set_cursor(self, tc):
self.Editor.setTextCursor(tc)
# Make a valid cursor based on position and anchor values possibly
# input by the user.
def make_cursor(self, position, anchor):
mx = self.document.characterCount()
tc = QTextCursor(self.Editor.textCursor())
anchor = min( max(0,anchor), mx )
position = min ( max(0,position), mx )
tc.setPosition(anchor)
tc.setPosition(position,QTextCursor.KeepAnchor)
return tc
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
# INITIALIZE UI
#
# First we built the Edit panel using Qt Creator which produced a large
# and somewhat opaque block of code that had to be mixed in by
# multiple inheritance. This had several drawbacks, so the following
# is a "manual" UI setup using code drawn from the generated code.
#
def _uic(self):
# First set up the properties of "self", a QWidget.
self.setObjectName("EditViewWidget")
sizePolicy = QSizePolicy(QSizePolicy.MinimumExpanding, QSizePolicy.MinimumExpanding)
sizePolicy.setHorizontalStretch(1)
sizePolicy.setVerticalStretch(1)
sizePolicy.setHeightForWidth(False) # don't care to bind height to width
self.setSizePolicy(sizePolicy)
self.setMinimumSize(QSize(250, 250))
self.setFocusPolicy(Qt.StrongFocus)
self.setContextMenuPolicy(Qt.CustomContextMenu)
self.setWindowTitle("")
self.setToolTip("")
self.setStatusTip("")
self.setWhatsThis("")
# Set up our primary widget, the editor
self.Editor = PTEditor(self,self.my_book)
self.Editor.setObjectName("Editor")
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
sizePolicy.setHorizontalStretch(2) # Edit deserves all available space
sizePolicy.setVerticalStretch(2)
sizePolicy.setHeightForWidth(False)
self.Editor.setSizePolicy(sizePolicy)
self.Editor.setFocusPolicy(Qt.StrongFocus)
self.Editor.setContextMenuPolicy(Qt.NoContextMenu)
self.Editor.setAcceptDrops(True)
self.Editor.setLineWidth(2)
self.Editor.setDocumentTitle("")
self.Editor.setLineWrapMode(QPlainTextEdit.NoWrap)
# Set up the frame that will contain the bottom row of widgets
# It doesn't need a parent and doesn't need to be a class member
# because it will be added to a layout, which parents it.
bot_frame = QFrame()
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(False)
bot_frame.setSizePolicy(sizePolicy)
bot_frame.setMinimumSize(QSize(0, 24))
bot_frame.setContextMenuPolicy(Qt.NoContextMenu)
bot_frame.setFrameShape(QFrame.Panel)
示例5: ConfigUI
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setFocusPolicy [as 別名]
class ConfigUI(QWidget):
configFilePath = ""
parseConfigSignal = pyqtSignal(etree._Element)
selectResGroupSignal = pyqtSignal(list)
def __init__(self, parent=None):
super(ConfigUI, self).__init__(parent)
grid = QGridLayout()
self.setLayout(grid)
##
grid.addWidget(QLabel("配置文件:"), 0, 0)
grid.addWidget(QLabel("資源分組:"), 1, 0)
grid.addWidget(QLabel("數據編碼:"), 2, 0)
##
self.configFileLE = QLineEdit()
# self.configFileLE.setEnabled(False)
self.configFileLE.setFocusPolicy(Qt.NoFocus)
grid.addWidget(self.configFileLE, 0, 1)
browsePB = QPushButton("瀏覽")
browsePB.clicked.connect(self.browse_config_path)
grid.addWidget(browsePB, 0, 2)
##
self.resGroupWidget = QWidget()
self.resGroupLayout = QHBoxLayout()
self.resGroupWidget.setLayout(self.resGroupLayout)
grid.addWidget(self.resGroupWidget, 1, 1)
selectPB = QPushButton("選擇")
selectPB.clicked.connect(self.select_res_group)
grid.addWidget(selectPB, 1, 2)
# def create_config
def browse_config_path(self):
open = QFileDialog()
# self.configFilePath = open.getOpenFileUrl(None, "選擇轉換列表文件")
self.configFilePath = open.getOpenFileName(None, "選擇轉換列表文件", "./")
self.configFileLE.setText(self.configFilePath[0])
if self.configFilePath[0] != "":
list = etree.parse(self.configFilePath[0])
root = list.getroot()
for item in root:
if item.tag == "ConvTree":
# 轉換樹
self.parseConfigSignal.emit(item)
elif item.tag == "ResStyleList":
# 資源分組
self.parse_res_group(item)
pass
def select_res_group(self):
groups = self.resGroupWidget.children()
if len(groups) > 0:
resGroupArr = []
for item in groups:
if isinstance(item, QCheckBox):
if item.isChecked():
resGroupArr.append(int(item.text().split(" ")[1]))
self.selectResGroupSignal.emit(resGroupArr)
def parse_res_group(self, item):
while self.resGroupLayout.count():
self.resGroupLayout.takeAt(0)
for node in item:
if node.tag != "ResStyle":
continue
print(node.attrib["Name"])
checkBox = QCheckBox(node.attrib["Name"] + " " + str(node.attrib["ID"]))
self.resGroupLayout.addWidget(checkBox)
self.resGroupLayout.addStretch()
示例6: SearchFrame
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setFocusPolicy [as 別名]
class SearchFrame(QWidget):
add_bunch_to_list_succeed = pyqtSignal()
listen_online_signal = pyqtSignal(str, str, str, str)
add_to_download_signal = pyqtSignal()
back_to_main_signal = pyqtSignal()
def __init__(self, parent = None):
super(SearchFrame, self).__init__(parent)
self.init_params()
self.setup_ui()
self.create_connections()
def setup_ui(self):
self.searchTable = SearchTable()
self.searchTable.setColumnWidth(0, 39)
self.searchTable.setColumnWidth(1, 205)
self.searchTable.setColumnWidth(2, 180)
self.searchTable.setColumnWidth(3, 180)
self.firstPageButton = QPushButton("首頁", clicked = self.jump_to_first_page)
self.firstPageButton.setFocusPolicy(Qt.NoFocus)
self.firstPageButton.setFixedHeight(31)
self.lastPageButton = QPushButton("末頁", clicked = self.jump_to_last_page)
self.lastPageButton.setFocusPolicy(Qt.NoFocus)
self.lastPageButton.setFixedHeight(31)
self.previousPageButton = QPushButton("上一頁")
self.previousPageButton.setFocusPolicy(Qt.NoFocus)
self.previousPageButton.setFixedHeight(31)
self.nextPageButton = QPushButton('下一頁')
self.nextPageButton.setFocusPolicy(Qt.NoFocus)
self.nextPageButton.setFixedHeight(31)
self.jumpNum = QLineEdit('0')
self.jumpNum.setFocusPolicy(Qt.StrongFocus)
self.jumpNum.setFixedSize(84, 31)
self.jumpNum.setAlignment(Qt.AlignRight | Qt.AlignVCenter)
self.pageNum = QLabel("/ 0")
self.pageNum.setFixedSize(45, 31)
self.pageNum.setAlignment(Qt.AlignLeft | Qt.AlignVCenter )
#頁碼欄布局
pageNumLayout = QHBoxLayout(self.jumpNum)
pageNumLayout.addStretch()
pageNumLayout.addWidget(self.pageNum)
pageNumLayout.setContentsMargins(0, 0, 0, 0)
pageNumLayout.setSpacing(0)
pageNumLayout.setContentsMargins(0, 0, 0, 0)
self.jumpNum.setTextMargins(0, 0, self.pageNum.width(), 0)
#綜合布局
self.controlWidget = QWidget()
controlLayout = QHBoxLayout(self.controlWidget)
controlLayout.setContentsMargins(0, 0, 0, 0)
controlLayout.setSpacing(6)
controlLayout.addWidget(self.firstPageButton)
controlLayout.addWidget(self.previousPageButton)
controlLayout.addWidget(self.jumpNum)
controlLayout.addWidget(self.nextPageButton)
controlLayout.addWidget(self.lastPageButton)
mainLayout = QVBoxLayout(self)
mainLayout.setSpacing(7)
mainLayout.setContentsMargins(0, 0, 0, 0)
mainLayout.addWidget(self.searchTable)
mainLayout.addWidget(self.controlWidget)
self.currentPage = 0
self.pages = 0
self.currentKeyword = ''
self.searchByType = 'all'
def create_connections(self):
self.previousPageButton.clicked.connect(self.previous_page)
self.nextPageButton.clicked.connect(self.next_page)
self.jumpNum.returnPressed.connect(self.go_to_page)
self.searchTable.cellDoubleClicked.connect(self.searchtable_clicked)
self.searchTable.cellClicked.connect(self.show_tooltip)
self.searchTable.listenOnlineAction.triggered.connect(self.listen_online)
self.searchTable.downloadAction.triggered.connect(self.download)
self.searchTable.addBunchToListAction.triggered.connect(self.add_bunch_to_list)
def init_params(self):
self.downloadDir = globalSettings.DownloadfilesPath
def set_download_dir(self, path):
self.downloadDir = path
def show_tooltip(self, row):
mark = self.searchTable.item(row, 0).text()
songName = self.searchTable.item(row, 1).text()
artist = self.searchTable.item(row, 2).text()
album = self.searchTable.item(row, 3).text()
self.searchTable.setToolTip("評分:%s\n 歌曲:%s\n歌手:%s\n專輯:%s"%(mark, songName, artist, album))
def listen_online(self):
if not self.searchTable.rowCount():
#.........這裏部分代碼省略.........