本文整理汇总了Python中PyQt5.QtGui.QPalette.setBrush方法的典型用法代码示例。如果您正苦于以下问题:Python QPalette.setBrush方法的具体用法?Python QPalette.setBrush怎么用?Python QPalette.setBrush使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtGui.QPalette
的用法示例。
在下文中一共展示了QPalette.setBrush方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NotesPanel
# 需要导入模块: from PyQt5.QtGui import QPalette [as 别名]
# 或者: from PyQt5.QtGui.QPalette import setBrush [as 别名]
class NotesPanel(QPlainTextEdit):
def __init__(self, my_book, parent=None):
super().__init__(parent)
self.book = my_book
# Where we store the last-sought-for find string
self.find_text = None
# Register to read and write metadata
my_book.get_meta_manager().register( C.MD_NO, self.read_meta, self.save_meta )
# Set our only font (we don't care about the general font, only mono)
# n.b. this gets the Book's default size as it hasn't loaded a document
# yet.
self.setFont(fonts.get_fixed(my_book.get_font_size()))
# hook up to be notified of a change in font choice
fonts.notify_me(self.font_change)
# Set up our document not using the default one
a_document = QTextDocument()
a_document.setDocumentLayout(QPlainTextDocumentLayout(a_document))
self.setDocument(a_document)
# Turn off linewrap mode
self.setLineWrapMode(QPlainTextEdit.NoWrap)
# The following kludge allows us to get the correct highlight
# color on focus-in. For unknown reasons Qt makes us use the
# "Inactive" color group even after focus-in. See focusInEvent()
# and focusOutEvent() below.
self.palette_active = QPalette(self.palette())
self.palette_inactive = QPalette(self.palette())
b = self.palette().brush(QPalette.Active,QPalette.Highlight)
self.palette_active.setBrush(QPalette.Inactive,QPalette.Highlight,b)
# Set the cursor shape to IBeam -- no idea why this supposed default
# inherited from QTextEdit, doesn't happen. But it doesn't.
self.viewport().setCursor(Qt.IBeamCursor)
# Hook up a slot to notice that the document has changed its
# modification state.
self.document().modificationChanged.connect(self.yikes)
# Create our edit menu and stow it in the menu bar. Disable it.
ed_menu = QMenu(C.ED_MENU_EDIT,self)
ed_menu.addAction(C.ED_MENU_UNDO,self.undo,QKeySequence.Undo)
ed_menu.addAction(C.ED_MENU_REDO,self.redo,QKeySequence.Redo)
ed_menu.addSeparator()
ed_menu.addAction(C.ED_MENU_CUT,self.cut,QKeySequence.Cut)
ed_menu.addAction(C.ED_MENU_COPY,self.copy,QKeySequence.Copy)
ed_menu.addAction(C.ED_MENU_PASTE,self.paste,QKeySequence.Paste)
ed_menu.addSeparator()
ed_menu.addAction(C.ED_MENU_FIND,self.find_action,QKeySequence.Find)
ed_menu.addAction(C.ED_MENU_NEXT,self.find_next_action,QKeySequence.FindNext)
self.edit_menu = mainwindow.get_menu_bar().addMenu(ed_menu)
self.edit_menu.setVisible(False)
# In order to get focus events, we need to set focus policy
self.setFocusPolicy(Qt.StrongFocus)
# Save the current notes text to a metadata file. Get each line of
# text (text block) in turn. If a line starts with '{{' (which might
# be a conflict with a metadata sentinel line) prefix it with u\fffd.
# This is what V.1 did, so we continue it.
def save_meta(self, qts, sentinel):
qts << metadata.open_line(sentinel)
tb = self.document().firstBlock()
while tb.isValid():
line = tb.text()
if line.startswith('{{'):
line = C.UNICODE_REPL + line
qts << line
qts << '\n'
tb = tb.next()
qts << metadata.close_line(sentinel)
# Read notes text from a metadata file. Clear our internal document just
# to be sure. Get each line from the input stream and append it to the
# document using the appendPlainText() method of the editor (which ought
# to be a method of the document, but whatever). Set the cursor to the
# top. Re-set the font in case the Book read a different size. Set our
# document to unmodified state.
def read_meta(self,qts,sentinel,version,parm):
self.document().clear()
for line in metadata.read_to(qts,sentinel):
if line.startswith(C.UNICODE_REPL+'{{'):
line = line[1:]
self.appendPlainText(line)
tc = QTextCursor(self.document())
tc.setPosition(0)
self.setTextCursor(tc)
self.document().setModified(False)
self.font_change(True) # update font selection
# Notify our book of a change in the modification state.
# This slot gets the modificationChanged(bool) signal from our
# document.
def yikes(self, boolean):
self.book.metadata_modified(boolean,C.MD_MOD_NO)
# Intercept the focus-in and -out events and use them to display
# and hide our edit menu.
def focusInEvent(self, event):
self.edit_menu.setVisible(True)
self.setPalette(self.palette_active)
def focusOutEvent(self, event):
self.edit_menu.setVisible(False)
self.setPalette(self.palette_inactive)
# Get notified of a change in the user's choice of font
#.........这里部分代码省略.........
示例2: Window
# 需要导入模块: from PyQt5.QtGui import QPalette [as 别名]
# 或者: from PyQt5.QtGui.QPalette import setBrush [as 别名]
class Window(QWidget):
child_windows = []
def __init__(self, path, parent=None):
super(Window, self).__init__()
self.setWindowTitle(path)
# self.pattern = "images/pattern.png"
self.pattern = os.path.dirname(os.path.realpath(__file__)) + "/images/pattern7.png"
self.path = path
self.widget = QWidget()
self.palette = QPalette()
self.palette.setBrush(
QPalette.Background, QBrush(QPixmap(self.pattern)))
self.widget.setPalette(self.palette)
layout = QVBoxLayout(self)
self._drag_widget = DragWidget(path)
self._drag_widget.windowclass_signal.connect(self.on_make_new_window)
self._drag_widget.query.connect(self.on_query)
layout.addWidget(self._drag_widget)
self.widget.setLayout(layout)
scroll = QScrollArea()
scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
scroll.setWidgetResizable(True)
scroll.setWidget(self.widget)
self.setStyleSheet("""
QScrollBar:vertical { border:none; width:6px }
QScrollBar::handle:vertical { background: lightgray; }
QScrollBar::add-line:vertical { background: none; }
QScrollBar::sub-line:vertical { background: none; }
QScrollBar:horizontal { border:none; height:6px }
QScrollBar::handle:horizontal { background: lightgray; }
QScrollBar::add-line:horizontal { background: none; }
QScrollBar::sub-line:horizontal { background: none; }
""")
vlayout = QVBoxLayout(self)
vlayout.setContentsMargins(0, 0, 0, 0)
vlayout.setSpacing(0)
vlayout.addWidget(scroll)
self.setLayout(vlayout)
self.show()
def closeEvent(self, event):
for item in Window.child_windows:
if item.windowTitle() == self.windowTitle():
Window.child_windows.remove(item)
item.deleteLater()
def on_make_new_window(self, path):
Window.child_windows.append(Window(os.path.realpath(path)))
def on_query(self):
# get info when doubleclicking on nothing in a window
print("got query=", self.windowTitle(),
"obj=", self, "type=", type(self),
"len child_windows=", len(Window.child_windows))
for item in Window.child_windows:
print("loop child_window=", type(
item), "title=", item.windowTitle())
示例3: Window
# 需要导入模块: from PyQt5.QtGui import QPalette [as 别名]
# 或者: from PyQt5.QtGui.QPalette import setBrush [as 别名]
class Window(QWidget):
child_windows = []
pattern = None
menu = None
modifier = False
def __init__(self, path, parent=None):
super(Window, self).__init__()
self.config = configparser.ConfigParser()
self.config.read('prefs.cfg')
if Window.menu is None:
Window.menu = GlobalMenu()
Window.menu.new_window_signal.connect(self.on_parent_window)
Window.menu.clean_up_signal.connect(self.on_clean_up)
Window.menu.delete_signal.connect(self.on_delete)
Window.menu.rename_signal.connect(self.on_rename)
Window.menu.file_signal.connect(self.on_file)
Window.menu.drawer_signal.connect(self.on_drawer)
Window.menu.trash_action_signal.connect(self.on_empty_trash)
self.setWindowTitle(path.rsplit('/', 1)[-1])
Window.pattern = self.config.get("background", "file")
self.path = path
self.widget = QWidget()
self.palette = QPalette()
self.palette.setBrush(
QPalette.Background, QBrush(QPixmap(self.pattern)))
self.widget.setPalette(self.palette)
layout = QVBoxLayout(self)
self._drag_widget = DragWidget(path, parent=self)
self._drag_widget.new_window_signal.connect(self.on_new_window)
self._drag_widget.query.connect(self.on_query)
layout.addWidget(self._drag_widget)
self.widget.setLayout(layout)
scroll = QScrollArea()
scroll.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
scroll.setHorizontalScrollBarPolicy(Qt.ScrollBarAsNeeded)
scroll.setWidgetResizable(True)
scroll.setWidget(self.widget)
vlayout = QVBoxLayout(self)
vlayout.setContentsMargins(0, 0, 0, 0)
vlayout.setSpacing(0)
vlayout.addWidget(scroll)
self.setLayout(vlayout)
Window.child_windows.append(self)
self.center()
self.show()
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def closeEvent(self, event):
for item in Window.child_windows:
if item.windowTitle() == self.windowTitle():
Window.child_windows.remove(item)
item.deleteLater()
def window_exists(self, path=None):
for item in Window.child_windows:
if item.path == path:
item.raise_()
return True
return False
def on_new_window(self, path):
if self.window_exists(path):
return
else:
Window(os.path.realpath(path))
def on_parent_window(self):
if self.isActiveWindow():
path = self.path.rsplit('/', 1)[0]
if path is "":
path = "/"
if self.window_exists(path):
return
else:
self.on_new_window(path)
def on_file(self):
if self.isActiveWindow():
print("create new file")
self._drag_widget.create_file()
pass
def on_drawer(self):
if self.isActiveWindow():
print("create new drawer")
self._drag_widget.create_drawer()
pass
def on_rename(self):
if self.isActiveWindow():
print("rename")
self._drag_widget.rename_file()
pass
#.........这里部分代码省略.........
示例4: setContentBackgroundColor
# 需要导入模块: from PyQt5.QtGui import QPalette [as 别名]
# 或者: from PyQt5.QtGui.QPalette import setBrush [as 别名]
def setContentBackgroundColor(self, color):
palette = QPalette(self.__content.palette())
palette.setBrush(QPalette.Background, color)
self.__content.setPalette(palette)
示例5: setBackgroundColor
# 需要导入模块: from PyQt5.QtGui import QPalette [as 别名]
# 或者: from PyQt5.QtGui.QPalette import setBrush [as 别名]
def setBackgroundColor(self, color):
palette = QPalette(self.palette())
palette.setBrush(QPalette.Background, color)
self.setPalette(palette)
示例6: setBackgroundImage
# 需要导入模块: from PyQt5.QtGui import QPalette [as 别名]
# 或者: from PyQt5.QtGui.QPalette import setBrush [as 别名]
def setBackgroundImage(self, image):
self._backgroundImage = QPixmap(image)
palette = QPalette(self.palette())
palette.setBrush(QPalette.Background, QBrush(self._backgroundImage))
self.setPalette(palette)