本文整理匯總了Python中PyQt5.QtWidgets.QLineEdit.setContextMenuPolicy方法的典型用法代碼示例。如果您正苦於以下問題:Python QLineEdit.setContextMenuPolicy方法的具體用法?Python QLineEdit.setContextMenuPolicy怎麽用?Python QLineEdit.setContextMenuPolicy使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類PyQt5.QtWidgets.QLineEdit
的用法示例。
在下文中一共展示了QLineEdit.setContextMenuPolicy方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Textfield
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setContextMenuPolicy [as 別名]
class Textfield(vip_base):
def cb_initialize_plugin(self):
self.event_change = DEvent('Change')
self.config = self.pl_get_current_config_ref()
self.pl_send_new_event_list([self.event_change])
self.pl_set_widget_for_internal_usage(self.create_widget())
return True
def create_widget(self):
self.lineedit = QLineEdit()
self.lineedit.returnPressed.connect(self.value_changed)
self.init_value = self.config['value_init']['value']
self.lineedit.setText(self.init_value)
self.lineedit.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.lineedit.customContextMenuRequested.connect(self.show_context_menu)
return self.lineedit
def show_context_menu(self, pos):
gloPos = self.lineedit.mapToGlobal(pos)
self.cmenu = self.pl_create_control_context_menu()
self.cmenu.exec_(gloPos)
def value_changed(self, change):
self.pl_emit_event(str(change), self.event_change)
def clicked(self):
pass
def cb_plugin_meta_updated(self):
pass
def cb_get_plugin_configuration(self):
config = {
'size': {
'value': "(150,60)",
'regex': '\(([0-9]+),([0-9]+)\)',
'advanced': 'Appearance',
'tooltip': 'Determine size: (height,width)'
},
'value_init': {
'value': '',
'tooltip': 'Used as initial value for the Textfield',
'advanced': 'Textfield'
},
'name': {
'value': 'PaPI Textfield',
'tooltip': 'Used for window title',
'advanced': 'Appearance',
}}
return config
def cb_quit(self):
pass
def value_changed(self):
change = self.lineedit.text()
self.pl_emit_event(str(change), self.event_change)
def cb_new_parameter_info(self, dparameter_object):
if isinstance(dparameter_object, DParameter):
value = dparameter_object.value
regex = dparameter_object.regex
if regex is not None:
rx = QtCore.QRegExp(regex)
validator = QRegExpValidator(rx, self.lineedit)
self.lineedit.setValidator(validator)
self.lineedit.returnPressed.disconnect()
self.lineedit.setText(str(value))
self.lineedit.returnPressed.connect(self.value_changed)
示例2: EditView
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setContextMenuPolicy [as 別名]
class EditView( QWidget ):
def __init__(self, my_book, focusser, parent=None):
# Initialize our superclass(es)
super().__init__(parent)
# Save the link to our book and the focus function
self.my_book = my_book
self.focusser = focusser # function to call on focus-in
# Save access to the document itself
self.document = my_book.get_edit_model()
# Save access to the word list and page data
self.word_model = my_book.get_word_model()
self.page_model = my_book.get_page_model()
# Initialize highlighting switches and create the highlighter.
self.highlighter = HighLighter(self,my_book)
self.scanno_check = False
self.spelling_check = False
#
# Take our UI setup out of line. self._uic creates and
# initializes all the sub-widgets under self. :
# .Editor - the QPlainTextEditor
# .DocName - QLabel for the document filename
# .Folio - QLabel for the current folio value
# .ImageFilename - QLineEdit for the current image filename
# .LineNumber - QLineEdit for the line number
# .ColNumber - QLabel for the cursor column
# Signals from these widgets are hooked up below.
#
self._uic()
# Connect the editor to the document.
self.Editor.setDocument(self.document)
# Set up mechanism for a current-line highlight and a find-range
# highlight. See set_find_range, clear_find_range, _set_colors
# and _cursor_moved.
self.last_text_block = None # to know when cursor moves to new line
self.current_line_sel = QTextEdit.ExtraSelection()
self.current_line_fmt = QTextCharFormat() # see _set_colors
self.current_line_fmt.setProperty(QTextFormat.FullWidthSelection, True)
self.range_sel = QTextEdit.ExtraSelection()
self.range_sel.cursor = QTextCursor(self.document) # null cursor
self.range_fmt = QTextCharFormat() # see _set_colors
self.range_fmt.setProperty(QTextCharFormat.FullWidthSelection, True)
self.extra_sel_list = [self.range_sel, self.current_line_sel]
# Sign up to get a signal on a change in font choice
fonts.notify_me(self.font_change)
# Fake that signal to set the fonts of our widgets.
self.one_line_height = 0 # updated in font_change
self.font_change(False)
# Sign up to get a signal on a change of color preferences.
colors.notify_me(self._set_colors)
# Fake the signal to set up widgets. This sets .scanno_format,
# .spelling_format, .current_line_sel, .range_sel, .norm_style and
# .mod_style.
self._set_colors()
# Put the document name in our widget
self.DocName.setText(self.my_book.get_book_name())
# Set the cursor shape to IBeam -- no idea why this supposed default
# inherited from QTextEdit, doesn't happen. But it doesn't.
# self.Editor.viewport().setCursor(Qt.IBeamCursor)
# Connect the Editor's modificationChanged signal to our slot.
self.Editor.modificationChanged.connect(self.mod_change_signal)
# Connect the returnPressed signal of the LineNumber widget
# to our go to line method.
self.LineNumber.returnPressed.connect(self._line_number_enter)
# Connect returnPressed of the ImageFilename widget to our slot.
self.ImageFilename.returnPressed.connect(self._image_enter)
# Connect the Editor's cursorPositionChanged signal to our slot
self.Editor.cursorPositionChanged.connect(self._cursor_moved)
# Fill in the line and column number by faking that signal
self._cursor_moved()
# Create and install our context menu
self.context_menu = self._make_context_menu()
self.setContextMenuPolicy(Qt.DefaultContextMenu)
# End of __init__()
# -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
# INTERNAL METHODS
# Set up text formats for the current line, spellcheck words
# and for scanno words. Done in a method because this has to be
# redone when the colorsChanged signal happens.
def _set_colors(self):
self.scanno_format = colors.get_scanno_format()
self.spelling_format = colors.get_spelling_format()
self.current_line_fmt.setBackground(colors.get_current_line_brush())
self.current_line_sel.format = QTextCharFormat(self.current_line_fmt)
self.range_fmt.setBackground(colors.get_find_range_brush())
self.range_sel.format = QTextCharFormat(self.range_fmt)
self.norm_style = 'color:Black;font-weight:normal;'
self.mod_style = 'color:' + colors.get_modified_color().name() + ';font-weight:bold;'
# Fake the mod-change signal to update the document name color
self.mod_change_signal(self.document.isModified())
# Slot to receive the modificationChanged signal from the document.
# Also called from the book when metadata changes state.
# Change the color of the DocName to match.
def mod_change_signal(self,bool):
self.DocName.setStyleSheet(self.mod_style if self.my_book.get_save_needed() else self.norm_style)
# This slot receives the ReturnPressed signal from the LineNumber field.
#.........這裏部分代碼省略.........
示例3: EditView
# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import setContextMenuPolicy [as 別名]
class EditView( QWidget ):
def __init__(self, my_book, focusser, parent=None):
# Initialize our superclass(es)
super().__init__(parent)
# Save the link to our book and the focus function
self.my_book = my_book
self.focusser = focusser # function to call on focus-in
# Save access to the document itself
self.document = my_book.get_edit_model()
# Save access to the word list and page data
self.word_model = my_book.get_word_model()
self.page_model = my_book.get_page_model()
# Initialize highlighting switches and create the highlighter.
self.highlighter = HighLighter(self,my_book)
self.scanno_check = False
self.spelling_check = False
self.my_book.get_meta_manager().register(C.MD_EH, self._read_switches, self._save_switches)
#
# Take our UI setup out of line. self._uic creates and
# initializes all the sub-widgets under self. :
# .Editor - the QPlainTextEditor
# .DocName - QLabel for the document filename
# .Folio - QLabel for the current folio value
# .ImageFilename - QLineEdit for the current image filename
# .LineNumber - QLineEdit for the line number
# .ColNumber - QLabel for the cursor column
# .norm_style - stylesheet for unmodified book name
# .mod_style - stylesheet for modified book name
# Signals from these widgets are hooked up below.
#
self._uic()
# Connect the editor to the document.
self.Editor.setDocument(self.document)
# Set up mechanism for a current-line highlight and a find-range
# highlight. This consists of a list of two "extra selections".
# An "extra selection" is basically a tuple of a cursor and a
# format. See set_find_range, clear_find_range, _set_colors
# and _cursor_moved.
self.last_text_block = None # to know when cursor moves to new line
self.current_line_sel = QTextEdit.ExtraSelection()
self.current_line_fmt = colors.get_current_line_format()
self.range_sel = QTextEdit.ExtraSelection()
self.range_sel.cursor = QTextCursor(self.document) # null cursor
self.extra_sel_list = [self.range_sel, self.current_line_sel]
# Sign up to get a signal on a change in font choice
fonts.notify_me(self.font_change)
# Fake that signal to set the fonts of our widgets.
self.one_line_height = 0 # updated in font_change
self.font_change(False)
# Sign up to get a signal on a change of color preferences.
colors.notify_me(self._set_colors)
# Fake the signal to set up widgets. This sets .scanno_format,
# .spelling_format, .current_line_sel, .range_sel, .norm_style and
# .mod_style.
self._set_colors()
# Put the document name in our widget
self.DocName.setText(self.my_book.get_book_name())
# Set the cursor shape to IBeam -- no idea why this supposed default
# inherited from QTextEdit, doesn't happen. But it doesn't.
# self.Editor.viewport().setCursor(Qt.IBeamCursor)
# Connect the Editor's modificationChanged signal to our slot.
self.Editor.modificationChanged.connect(self.mod_change_signal)
# Connect the returnPressed signal of the LineNumber widget
# to our go to line method.
self.LineNumber.returnPressed.connect(self._line_number_enter)
# Connect returnPressed of the ImageFilename widget to our slot.
self.ImageFilename.returnPressed.connect(self._image_enter)
# Connect the Editor's cursorPositionChanged signal to our slot
self.Editor.cursorPositionChanged.connect(self._cursor_moved)
# Fill in the line and column number by faking that signal
self._cursor_moved()
# Create and install our context menu
self.context_menu = self._make_context_menu()
self.setContextMenuPolicy(Qt.DefaultContextMenu)
# Hideous hack: the Book calls center_this with the cursor value
# read from the metadata. However at that time the editor is
# (apparently) not fully initialized and although the cursor is
# set, it is not in the center of the window. We looked and looked
# for some event that reliably means the editor is ready to display
# and settled on paintEvent. If center_this has been called before
# the first paint event, the call is repeated.
self.first_paint_event = True
self.first_center_tc = None
# End of __init__()
def paintEvent(self, event):
super().paintEvent(event)
if self.first_paint_event :
self.first_paint_event = False
if self.first_center_tc is not None :
self.center_this( self.first_center_tc )
self.first_center_tc = None
# Metadata load and save of the scanno/spelling highlight switches
def _save_switches(self, section):
return (self.scanno_check, self.spelling_check)
def _read_switches(self, sentinel, value, version):
# check that value is a tuple of two ints and ignore it if not
#.........這裏部分代碼省略.........