當前位置: 首頁>>代碼示例>>Python>>正文


Python QLineEdit.palette方法代碼示例

本文整理匯總了Python中PyQt5.QtWidgets.QLineEdit.palette方法的典型用法代碼示例。如果您正苦於以下問題:Python QLineEdit.palette方法的具體用法?Python QLineEdit.palette怎麽用?Python QLineEdit.palette使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在PyQt5.QtWidgets.QLineEdit的用法示例。


在下文中一共展示了QLineEdit.palette方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: PathChoice

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import palette [as 別名]
class PathChoice(ChoiceWidget):
    def __init__( self, criterion, title, explainer ) :
        super().__init__( title, explainer )
        self.criterion = criterion
        self.path_edit = QLineEdit()
        self.path_valid = True
        self.path_edit.textChanged.connect( self.path_working )
        self.path_edit.editingFinished.connect( self.check_path )
        self.browse_button = QPushButton(
            _TR('Path preference button', 'Browse' ) )
        self.browse_button.clicked.connect( self.browse )
        self.layout().addWidget( self.path_edit, 1 )
        self.layout().addWidget( self.browse_button, 0 )

    # Change the color of the background of the path_edit.
    def set_path_color( self, color_name ) :
        p = self.path_edit.palette()
        p.setColor( QPalette.Normal, QPalette.Base, QColor( color_name ) )
        self.path_edit.setPalette(p)

    # User is editing the path string. If it is now marked invalid,
    # clear that and make its background white again.
    def path_working( self ) :
        if self.path_valid : return
        self.path_valid = True
        self.set_path_color('White')

    # Return pressed or focus-out of the path line-edit. Check for
    # validity per the criterion.
    def check_path( self ) :
        if os.access( self.path_edit.text(), self.criterion ) :
            return
        if self.path_edit.text() : # is not null
            utilities.beep()
            self.path_valid = False
            self.set_path_color( 'Pink' )

    # User wants to browse for a path. The subclass must implement
    # this by calling a utilities dialog with a specific caption.

    def browse(self) :
        pass
開發者ID:tallforasmurf,項目名稱:PPQT2,代碼行數:44,代碼來源:preferences.py

示例2: ReTextWindow

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import palette [as 別名]

#.........這裏部分代碼省略.........
		self.searchBar.addAction(self.actionCloseSearch)
		self.searchBar.setToolButtonStyle(Qt.ToolButtonTextBesideIcon)
		self.searchBar.setVisible(False)
		self.autoSaveEnabled = globalSettings.autoSave
		if self.autoSaveEnabled:
			timer = QTimer(self)
			timer.start(60000)
			timer.timeout.connect(self.saveAll)
		self.ind = None
		if enchant_available:
			self.sl = globalSettings.spellCheckLocale
			if self.sl:
				try:
					enchant.Dict(self.sl)
				except Exception as e:
					print(e, file=sys.stderr)
					self.sl = None
			if globalSettings.spellCheck:
				self.actionEnableSC.setChecked(True)
		self.fileSystemWatcher = QFileSystemWatcher()
		self.fileSystemWatcher.fileChanged.connect(self.fileChanged)

	def iterateTabs(self):
		for i in range(self.tabWidget.count()):
			yield self.tabWidget.widget(i).tab

	def updateStyleSheet(self):
		if globalSettings.styleSheet:
			sheetfile = QFile(globalSettings.styleSheet)
			sheetfile.open(QIODevice.ReadOnly)
			self.ss = QTextStream(sheetfile).readAll()
			sheetfile.close()
		else:
			palette = QApplication.palette()
			self.ss = 'html { color: %s; }\n' % palette.color(QPalette.WindowText).name()
			self.ss += 'td, th { border: 1px solid #c3c3c3; padding: 0 3px 0 3px; }\n'
			self.ss += 'table { border-collapse: collapse; }\n'

	def initTabWidget(self):
		def dragEnterEvent(e):
			e.acceptProposedAction()
		def dropEvent(e):
			fn = bytes(e.mimeData().data('text/plain')).decode().rstrip()
			if fn.startswith('file:'):
				fn = QUrl(fn).toLocalFile()
			self.openFileWrapper(fn)
		self.tabWidget.setTabsClosable(True)
		self.tabWidget.setAcceptDrops(True)
		self.tabWidget.setMovable(True)
		self.tabWidget.dragEnterEvent = dragEnterEvent
		self.tabWidget.dropEvent = dropEvent

	def act(self, name, icon=None, trig=None, trigbool=None, shct=None):
		if not isinstance(shct, QKeySequence):
			shct = QKeySequence(shct)
		if icon:
			action = QAction(self.actIcon(icon), name, self)
		else:
			action = QAction(name, self)
		if trig:
			action.triggered.connect(trig)
		elif trigbool:
			action.setCheckable(True)
			action.triggered[bool].connect(trigbool)
		if shct:
			action.setShortcut(shct)
開發者ID:daffodil,項目名稱:retext,代碼行數:70,代碼來源:window.py

示例3: RegExpDialog

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import palette [as 別名]
class RegExpDialog(QDialog):
    MaxCaptures = 6

    def __init__(self, parent=None):
        super(RegExpDialog, self).__init__(parent)

        self.patternComboBox = QComboBox()
        self.patternComboBox.setEditable(True)
        self.patternComboBox.setSizePolicy(QSizePolicy.Expanding,
                QSizePolicy.Preferred)

        patternLabel = QLabel("&Pattern:")
        patternLabel.setBuddy(self.patternComboBox)

        self.escapedPatternLineEdit = QLineEdit()
        self.escapedPatternLineEdit.setReadOnly(True)
        palette = self.escapedPatternLineEdit.palette()
        palette.setBrush(QPalette.Base,
                palette.brush(QPalette.Disabled, QPalette.Base))
        self.escapedPatternLineEdit.setPalette(palette)

        escapedPatternLabel = QLabel("&Escaped Pattern:")
        escapedPatternLabel.setBuddy(self.escapedPatternLineEdit)

        self.syntaxComboBox = QComboBox()
        self.syntaxComboBox.addItem("Regular expression v1", QRegExp.RegExp)
        self.syntaxComboBox.addItem("Regular expression v2", QRegExp.RegExp2)
        self.syntaxComboBox.addItem("Wildcard", QRegExp.Wildcard)
        self.syntaxComboBox.addItem("Fixed string", QRegExp.FixedString)

        syntaxLabel = QLabel("&Pattern Syntax:")
        syntaxLabel.setBuddy(self.syntaxComboBox)

        self.textComboBox = QComboBox()
        self.textComboBox.setEditable(True)
        self.textComboBox.setSizePolicy(QSizePolicy.Expanding,
                QSizePolicy.Preferred)

        textLabel = QLabel("&Text:")
        textLabel.setBuddy(self.textComboBox)

        self.caseSensitiveCheckBox = QCheckBox("Case &Sensitive")
        self.caseSensitiveCheckBox.setChecked(True)
        self.minimalCheckBox = QCheckBox("&Minimal")

        indexLabel = QLabel("Index of Match:")
        self.indexEdit = QLineEdit()
        self.indexEdit.setReadOnly(True)

        matchedLengthLabel = QLabel("Matched Length:")
        self.matchedLengthEdit = QLineEdit()
        self.matchedLengthEdit.setReadOnly(True)

        self.captureLabels = []
        self.captureEdits = []
        for i in range(self.MaxCaptures):
            self.captureLabels.append(QLabel("Capture %d:" % i))
            self.captureEdits.append(QLineEdit())
            self.captureEdits[i].setReadOnly(True)
        self.captureLabels[0].setText("Match:")

        checkBoxLayout = QHBoxLayout()
        checkBoxLayout.addWidget(self.caseSensitiveCheckBox)
        checkBoxLayout.addWidget(self.minimalCheckBox)
        checkBoxLayout.addStretch(1)

        mainLayout = QGridLayout()
        mainLayout.addWidget(patternLabel, 0, 0)
        mainLayout.addWidget(self.patternComboBox, 0, 1)
        mainLayout.addWidget(escapedPatternLabel, 1, 0)
        mainLayout.addWidget(self.escapedPatternLineEdit, 1, 1)
        mainLayout.addWidget(syntaxLabel, 2, 0)
        mainLayout.addWidget(self.syntaxComboBox, 2, 1)
        mainLayout.addLayout(checkBoxLayout, 3, 0, 1, 2)
        mainLayout.addWidget(textLabel, 4, 0)
        mainLayout.addWidget(self.textComboBox, 4, 1)
        mainLayout.addWidget(indexLabel, 5, 0)
        mainLayout.addWidget(self.indexEdit, 5, 1)
        mainLayout.addWidget(matchedLengthLabel, 6, 0)
        mainLayout.addWidget(self.matchedLengthEdit, 6, 1)

        for i in range(self.MaxCaptures):
            mainLayout.addWidget(self.captureLabels[i], 7 + i, 0)
            mainLayout.addWidget(self.captureEdits[i], 7 + i, 1)
        self.setLayout(mainLayout)

        self.patternComboBox.editTextChanged.connect(self.refresh)
        self.textComboBox.editTextChanged.connect(self.refresh)
        self.caseSensitiveCheckBox.toggled.connect(self.refresh)
        self.minimalCheckBox.toggled.connect(self.refresh)
        self.syntaxComboBox.currentIndexChanged.connect(self.refresh)

        self.patternComboBox.addItem("[A-Za-z_]+([A-Za-z_0-9]*)")
        self.textComboBox.addItem("(10 + delta4)* 32")

        self.setWindowTitle("RegExp")
        self.setFixedHeight(self.sizeHint().height())
        self.refresh()

    def refresh(self):
#.........這裏部分代碼省略.........
開發者ID:Axel-Erfurt,項目名稱:pyqt5,代碼行數:103,代碼來源:regexp.py

示例4: ReTextWindow

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import palette [as 別名]

#.........這裏部分代碼省略.........
				self.enableSpellCheck(self.actionEnableSC.isChecked())
		else:
			self.sl = None
			self.enableSpellCheck(self.actionEnableSC.isChecked())
		if setdefault:
			globalSettings.spellCheckLocale = sl

	def searchBarVisibilityChanged(self, visible):
		self.actionSearch.setChecked(visible)
		if visible:
			self.searchEdit.setFocus(Qt.ShortcutFocusReason)

	def find(self, back=False):
		flags = QTextDocument.FindFlags()
		if back:
			flags |= QTextDocument.FindBackward
		if self.csBox.isChecked():
			flags |= QTextDocument.FindCaseSensitively
		text = self.searchEdit.text()
		editBox = self.editBoxes[self.ind]
		cursor = editBox.textCursor()
		newCursor = editBox.document().find(text, cursor, flags)
		if not newCursor.isNull():
			editBox.setTextCursor(newCursor)
			return self.setSearchEditColor(True)
		cursor.movePosition(QTextCursor.End if back else QTextCursor.Start)
		newCursor = editBox.document().find(text, cursor, flags)
		if not newCursor.isNull():
			editBox.setTextCursor(newCursor)
			return self.setSearchEditColor(True)
		self.setSearchEditColor(False)

	def setSearchEditColor(self, found):
		palette = self.searchEdit.palette()
		palette.setColor(QPalette.Active, QPalette.Base,
		                 Qt.white if found else QColor(255, 102, 102))
		self.searchEdit.setPalette(palette)

	def getHtml(self, includeStyleSheet=True, includeTitle=True,
	            includeMeta=False, webenv=False):
		if self.markups[self.ind] is None:
			markupClass = self.getMarkupClass()
			errMsg = self.tr('Could not parse file contents, check if '
			'you have the <a href="%s">necessary module</a> installed!')
			try:
				errMsg %= markupClass.attributes[MODULE_HOME_PAGE]
			except (AttributeError, KeyError):
				# Remove the link if markupClass doesn't have the needed attribute
				errMsg = errMsg.replace('<a href="%s">', '')
				errMsg = errMsg.replace('</a>', '')
			return '<p style="color: red">%s</p>' % errMsg
		text = self.editBoxes[self.ind].toPlainText()
		headers = ''
		if includeStyleSheet:
			headers += '<style type="text/css">\n' + self.ss + '</style>\n'
		cssFileName = self.getDocumentTitle(baseName=True)+'.css'
		if QFile(cssFileName).exists():
			headers += '<link rel="stylesheet" type="text/css" href="%s">\n' \
			% cssFileName
		if includeMeta:
			headers += ('<meta name="generator" content="ReText %s">\n' %
			            app_version)
		fallbackTitle = self.getDocumentTitle() if includeTitle else ''
		return self.markups[self.ind].get_whole_html(text,
			custom_headers=headers, include_stylesheet=includeStyleSheet,
			fallback_title=fallbackTitle, webenv=webenv)
開發者ID:zisecheng,項目名稱:retext,代碼行數:70,代碼來源:window.py

示例5: FileEdit

# 需要導入模塊: from PyQt5.QtWidgets import QLineEdit [as 別名]
# 或者: from PyQt5.QtWidgets.QLineEdit import palette [as 別名]
class FileEdit(QWidget):
    filePathChanged = pyqtSignal(str)

    def __init__(self, parent = None):
        super().__init__(parent)

        self.mFilter = ''
        self.mErrorTextColor = Qt.red

        layout = QHBoxLayout(self)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.setSpacing(0)
        self.mLineEdit = QLineEdit(self)
        self.mLineEdit.setSizePolicy(QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Preferred))
        self.mOkTextColor = self.mLineEdit.palette().color(QPalette.Active, QPalette.Text)
        button = QToolButton(self)
        button.setSizePolicy(QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Preferred))
        button.setFixedWidth(20)
        button.setText("...")
        layout.addWidget(self.mLineEdit)
        layout.addWidget(button)
        self.setFocusProxy(self.mLineEdit)
        self.setFocusPolicy(Qt.StrongFocus)
        self.setAttribute(Qt.WA_InputMethodEnabled)
        self.mLineEdit.textEdited.connect(self.filePathChanged)
        self.mLineEdit.textChanged.connect(self.validate)
        button.clicked.connect(self.buttonClicked)

    def setFilePath(self, filePath):
         if (self.mLineEdit.text() != filePath):
             self.mLineEdit.setText(filePath)

    def filePath(self):
        return self.mLineEdit.text()

    def setFilter(self, filter):
        self.mFilter = filter

    def focusInEvent(self, e):
        self.mLineEdit.event(e)
        if (e.reason() == Qt.TabFocusReason or e.reason() == Qt.BacktabFocusReason):
            self.mLineEdit.selectAll()

        super().focusInEvent(e)

    def focusOutEvent(self, e):
        self.mLineEdit.event(e)
        super().focusOutEvent(e)

    def keyPressEvent(self, e):
        self.mLineEdit.event(e)

    def keyReleaseEvent(self, e):
        self.mLineEdit.event(e)

    def validate(self, text):
        if QFile.exists(text):
            textColor = self.mOkTextColor
        else:
            textColor = self.mErrorTextColor
        palette = self.mLineEdit.palette()
        palette.setColor(QPalette.Active, QPalette.Text, textColor)
        self.mLineEdit.setPalette(palette)

    def buttonClicked(self):
        filePath, _ = QFileDialog.getOpenFileName(self.window(), self.tr("Choose a File"), self.mLineEdit.text(), self.mFilter)
        if filePath=='':
            return
        self.mLineEdit.setText(filePath)
        self.filePathChanged.emit(filePath)
開發者ID:theall,項目名稱:Python-Tiled,代碼行數:72,代碼來源:fileedit.py


注:本文中的PyQt5.QtWidgets.QLineEdit.palette方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。