本文整理汇总了Python中PyQt5.QtWidgets.QWidget.setPalette方法的典型用法代码示例。如果您正苦于以下问题:Python QWidget.setPalette方法的具体用法?Python QWidget.setPalette怎么用?Python QWidget.setPalette使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt5.QtWidgets.QWidget
的用法示例。
在下文中一共展示了QWidget.setPalette方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: iWindow
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setPalette [as 别名]
class iWindow(iWidget):
def __init__(self,
parent=None,
buttons=('min', 'max', 'close')
):
super(iWindow, self).__init__(parent)
self.borderMargin = 5
self.setBackgroundColor(QColor(107, 173, 246))
self.__mainLayout = QVBoxLayout()
self.__mainLayout.setSpacing(0)
self.__mainLayout.setContentsMargins(0, 0, 0, 0)
self.__contentLayout = QVBoxLayout()
self.__contentLayout.setSpacing(0)
self.__titleBar = iTitleBar(self, buttons=buttons)
self.__content = QWidget()
self.__content.setMouseTracking(True)
self.__content.setAutoFillBackground(True)
self.__contentLayout.addWidget(self.__content)
self.__mainLayout.addWidget(self.__titleBar)
self.__mainLayout.addLayout(self.__contentLayout)
self.setBorderWidth(self.borderMargin, 0,
self.borderMargin, self.borderMargin)
self.setContentBackgroundColor(QColor(242, 242, 242))
QWidget.setLayout(self, self.__mainLayout)
''' Overrides APIs. '''
def setLayout(self, layout):
self.__content.setLayout(layout)
def setContentsMargins(self, left=0, top=0, right=0, bottom=0):
self.__content.setContentsMargins(left, top, right, bottom)
''' Extends APIs. '''
def setBorderWidth(self, left=0, top=0, right=0, bottom=0):
self.__contentLayout.setContentsMargins(left, top, right, bottom)
def titleBar(self):
return self.__titleBar
def setIcon(self, icon=''):
self._titleBar.setIcon(icon)
def setTitle(self, title=''):
self._titleBar.setTitle(title)
def setTitleBarColor(self, color):
p = self._titleBar.palette()
p.setColor(QPalette.WindowText, color)
self._titleBar.setPalette(p)
def setContentBackgroundColor(self, color):
palette = QPalette(self.__content.palette())
palette.setBrush(QPalette.Background, color)
self.__content.setPalette(palette)
示例2: Window
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setPalette [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.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setPalette [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: _build_gui
# 需要导入模块: from PyQt5.QtWidgets import QWidget [as 别名]
# 或者: from PyQt5.QtWidgets.QWidget import setPalette [as 别名]
def _build_gui(self):
# Storages
buttons = self._buttons
# Unpack dimension data
x, y, width, height = CACHE['dimension']
# If position have not been set before
if x is NotImplemented:
screen = QDesktopWidget().screenGeometry()
x, y = (screen.width() - width) / 2, (screen.height() - height) / 2
# Set window position and dimension
self.setGeometry(x, y, width, height)
self.setFixedWidth(width)
# Create layout for the entire application and zero-out
self.layout = main_layout = QVBoxLayout()
main_layout.setSpacing(0)
main_layout.setContentsMargins(0, 0, 0, 0)
# Create and add scrollable area for streams
self._scroll_area = posts = QScrollArea()
posts.setWidgetResizable(True)
posts.setVerticalScrollBarPolicy(Qt.ScrollBarAlwaysOn)
posts.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
posts.setFrameShape(QFrame.NoFrame)
# Create a main-stream widget
main_stream = QWidget()
main_stream.setFixedWidth(width)
# TODO: rename self._posts to something meaningful
self._posts = posts_layout = QVBoxLayout()
posts_layout.setSpacing(POST_SPACING_FULL)
posts_layout.setContentsMargins(0, 0, 0, 0)
# HACK: in both scroll arrows the 'padding_left' value is a hack.
# The reason why the arrows are not aligned to the horizontal
# center is unknown as it looks like everything is set up properly
# Add scroll-up icon and text
self._scroll_up = CoubletButtonWidget(icon=CONSTANTS['icon_scroll_up'],
label='SCROLL UP TO REFRESH',
font=CONSTANTS['text_font_generic'],
palette=CONSTANTS['text_color_light'],
order=ICON_AND_LABEL,
orientation=VERTICAL,
spacing=SMALL_PADDING,
padding_top=POST_SPACING_FULL,
padding_left=8)
posts_layout.addWidget(self._scroll_up, alignment=Qt.AlignHCenter)
# Dynamic space
posts_layout.addStretch(0)
# Add scroll-down icon and text
self._scroll_down = CoubletButtonWidget(icon=CONSTANTS['icon_scroll_down'],
label='SCROLL DOWN TO LOAD MORE',
font=CONSTANTS['text_font_generic'],
palette=CONSTANTS['text_color_light'],
order=LABEL_AND_ICON,
orientation=VERTICAL,
spacing=SMALL_PADDING,
padding_bottom=POST_SPACING_FULL,
padding_left=8)
posts_layout.addWidget(self._scroll_down, alignment=Qt.AlignHCenter)
# Set posts' layout to stream, add stream to main layout
main_stream.setLayout(posts_layout)
posts.setWidget(main_stream)
main_layout.addWidget(posts)
# Create menu-bar
menu_bar = QWidget()
menu_bar.setPalette(CONSTANTS['panel_color_darker'])
menu_bar.setAutoFillBackground(True)
# Create layout for menu-bar and zero-out
menu_bar_layout = QVBoxLayout()
menu_bar_layout.setSpacing(0)
menu_bar_layout.setContentsMargins(0, 0, 0, 0)
# Create layout for menu buttons and zero-out
menu_buttons_layout = QHBoxLayout()
menu_buttons_layout.setSpacing(0)
menu_buttons_layout.setContentsMargins(0, 0, 0, 0)
# Add menu-buttons to menu-bar
menu_bar_layout.addSpacing(2*SMALL_PADDING)
menu_bar_layout.addLayout(menu_buttons_layout)
menu_bar_layout.addSpacing(2*SMALL_PADDING)
# Assign layout and add menu-bar to app
menu_bar.setLayout(menu_bar_layout)
main_layout.addWidget(menu_bar)
# Add buttons and spacess to menu-buttons layout
menu_buttons_layout.addSpacing(2*SMALL_PADDING)
# get default double-click interval
for i, menu_item in enumerate(CoubAPI.STREAM_NAMES):
# If not the first item, add
# auto-stretching before it
#.........这里部分代码省略.........