mirror of
https://github.com/Wanderson-Magalhaes/PyOneDark_Qt_Widgets_Modern_GUI.git
synced 2026-08-06 07:23:22 +00:00
09/06/2021
This commit is contained in:
+21
-1
@@ -40,4 +40,24 @@ from . py_title_bar import PyTitleBar
|
||||
|
||||
# PY CREDITS
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from . py_credits_bar import PyCredits
|
||||
from . py_credits_bar import PyCredits
|
||||
|
||||
# PY PUSH BUTTON
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from . py_push_button import PyPushButton
|
||||
|
||||
# PY TOGGLE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from . py_toggle import PyToggle
|
||||
|
||||
# PY SLIDER
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from . py_slider import PySlider
|
||||
|
||||
# PY CIRCULAR PROGRESS
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from . py_circular_progress import PyCircularProgress
|
||||
|
||||
# PY ICON BUTTON
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from . py_icon_button import PyIconButton
|
||||
@@ -0,0 +1,19 @@
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
#
|
||||
# BY: WANDERSON M.PIMENTA
|
||||
# PROJECT MADE WITH: Qt Designer and PySide6
|
||||
# V: 1.0.0
|
||||
#
|
||||
# This project can be used freely for all uses, as long as they maintain the
|
||||
# respective credits only in the Python scripts, any information in the visual
|
||||
# interface (GUI) can be modified without any implication.
|
||||
#
|
||||
# There are limitations on Qt licenses if you want to use your products
|
||||
# commercially, I recommend reading them on the official website:
|
||||
# https://doc.qt.io/qtforpython/licenses.html
|
||||
#
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
|
||||
# PY TITLE BAR
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from . py_circular_progress import PyCircularProgress
|
||||
@@ -0,0 +1,114 @@
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
#
|
||||
# BY: WANDERSON M.PIMENTA
|
||||
# PROJECT MADE WITH: Qt Designer and PySide6
|
||||
# V: 1.0.0
|
||||
#
|
||||
# This project can be used freely for all uses, as long as they maintain the
|
||||
# respective credits only in the Python scripts, any information in the visual
|
||||
# interface (GUI) can be modified without any implication.
|
||||
#
|
||||
# There are limitations on Qt licenses if you want to use your products
|
||||
# commercially, I recommend reading them on the official website:
|
||||
# https://doc.qt.io/qtforpython/licenses.html
|
||||
#
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
|
||||
# IMPORT QT CORE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from qt_core import *
|
||||
|
||||
class PyCircularProgress(QWidget):
|
||||
def __init__(
|
||||
self,
|
||||
value = 0,
|
||||
progress_width = 10,
|
||||
is_rounded = True,
|
||||
max_value = 100,
|
||||
progress_color = "#ff79c6",
|
||||
enable_text = True,
|
||||
font_family = "Segoe UI",
|
||||
font_size = 12,
|
||||
suffix = "%",
|
||||
text_color = "#ff79c6",
|
||||
enable_bg = True,
|
||||
bg_color = "#44475a"
|
||||
):
|
||||
QWidget.__init__(self)
|
||||
|
||||
# CUSTOM PROPERTIES
|
||||
self.value = value
|
||||
self.progress_width = progress_width
|
||||
self.progress_rounded_cap = is_rounded
|
||||
self.max_value = max_value
|
||||
self.progress_color = progress_color
|
||||
# Text
|
||||
self.enable_text = enable_text
|
||||
self.font_family = font_family
|
||||
self.font_size = font_size
|
||||
self.suffix = suffix
|
||||
self.text_color = text_color
|
||||
# BG
|
||||
self.enable_bg = enable_bg
|
||||
self.bg_color = bg_color
|
||||
|
||||
# ADD DROPSHADOW
|
||||
def add_shadow(self, enable):
|
||||
if enable:
|
||||
self.shadow = QGraphicsDropShadowEffect(self)
|
||||
self.shadow.setBlurRadius(15)
|
||||
self.shadow.setXOffset(0)
|
||||
self.shadow.setYOffset(0)
|
||||
self.shadow.setColor(QColor(0, 0, 0, 80))
|
||||
self.setGraphicsEffect(self.shadow)
|
||||
|
||||
# SET VALUE
|
||||
def set_value(self, value):
|
||||
self.value = value
|
||||
self.repaint() # Render progress bar after change value
|
||||
|
||||
|
||||
# PAINT EVENT (DESIGN YOUR CIRCULAR PROGRESS HERE)
|
||||
def paintEvent(self, e):
|
||||
# SET PROGRESS PARAMETERS
|
||||
width = self.width() - self.progress_width
|
||||
height = self.height() - self.progress_width
|
||||
margin = self.progress_width / 2
|
||||
value = self.value * 360 / self.max_value
|
||||
|
||||
# PAINTER
|
||||
paint = QPainter()
|
||||
paint.begin(self)
|
||||
paint.setRenderHint(QPainter.Antialiasing) # remove pixelated edges
|
||||
paint.setFont(QFont(self.font_family, self.font_size))
|
||||
|
||||
# CREATE RECTANGLE
|
||||
rect = QRect(0, 0, self.width(), self.height())
|
||||
paint.setPen(Qt.NoPen)
|
||||
|
||||
# PEN
|
||||
pen = QPen()
|
||||
pen.setWidth(self.progress_width)
|
||||
# Set Round Cap
|
||||
if self.progress_rounded_cap:
|
||||
pen.setCapStyle(Qt.RoundCap)
|
||||
|
||||
# ENABLE BG
|
||||
if self.enable_bg:
|
||||
pen.setColor(QColor(self.bg_color))
|
||||
paint.setPen(pen)
|
||||
paint.drawArc(margin, margin, width, height, 0, 360 * 16)
|
||||
|
||||
# CREATE ARC / CIRCULAR PROGRESS
|
||||
pen.setColor(QColor(self.progress_color))
|
||||
paint.setPen(pen)
|
||||
paint.drawArc(margin, margin, width, height, -90 * 16, -value * 16)
|
||||
|
||||
# CREATE TEXT
|
||||
if self.enable_text:
|
||||
pen.setColor(QColor(self.text_color))
|
||||
paint.setPen(pen)
|
||||
paint.drawText(rect, Qt.AlignCenter, f"{self.value}{self.suffix}")
|
||||
|
||||
# END
|
||||
paint.end()
|
||||
@@ -0,0 +1,19 @@
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
#
|
||||
# BY: WANDERSON M.PIMENTA
|
||||
# PROJECT MADE WITH: Qt Designer and PySide6
|
||||
# V: 1.0.0
|
||||
#
|
||||
# This project can be used freely for all uses, as long as they maintain the
|
||||
# respective credits only in the Python scripts, any information in the visual
|
||||
# interface (GUI) can be modified without any implication.
|
||||
#
|
||||
# There are limitations on Qt licenses if you want to use your products
|
||||
# commercially, I recommend reading them on the official website:
|
||||
# https://doc.qt.io/qtforpython/licenses.html
|
||||
#
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
|
||||
# PY ICON BUTTON
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from . py_icon_button import PyIconButton
|
||||
@@ -0,0 +1,268 @@
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
#
|
||||
# BY: WANDERSON M.PIMENTA
|
||||
# PROJECT MADE WITH: Qt Designer and PySide6
|
||||
# V: 1.0.0
|
||||
#
|
||||
# This project can be used freely for all uses, as long as they maintain the
|
||||
# respective credits only in the Python scripts, any information in the visual
|
||||
# interface (GUI) can be modified without any implication.
|
||||
#
|
||||
# There are limitations on Qt licenses if you want to use your products
|
||||
# commercially, I recommend reading them on the official website:
|
||||
# https://doc.qt.io/qtforpython/licenses.html
|
||||
#
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
|
||||
# IMPORT QT CORE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from qt_core import *
|
||||
|
||||
# PY TITLE BUTTON
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
class PyIconButton(QPushButton):
|
||||
def __init__(
|
||||
self,
|
||||
icon_path = None,
|
||||
parent = None,
|
||||
app_parent = None,
|
||||
tooltip_text = "",
|
||||
btn_id = None,
|
||||
width = 30,
|
||||
height = 30,
|
||||
radius = 8,
|
||||
bg_color = "#343b48",
|
||||
bg_color_hover = "#3c4454",
|
||||
bg_color_pressed = "#2c313c",
|
||||
icon_color = "#c3ccdf",
|
||||
icon_color_hover = "#dce1ec",
|
||||
icon_color_pressed = "#edf0f5",
|
||||
icon_color_active = "#f5f6f9",
|
||||
dark_one = "#1b1e23",
|
||||
text_foreground = "#8a95aa",
|
||||
context_color = "#568af2",
|
||||
top_margin = 40,
|
||||
is_active = False
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
# SET DEFAULT PARAMETERS
|
||||
self.setFixedSize(width, height)
|
||||
self.setCursor(Qt.PointingHandCursor)
|
||||
self.setObjectName(btn_id)
|
||||
|
||||
# PROPERTIES
|
||||
self._bg_color = bg_color
|
||||
self._bg_color_hover = bg_color_hover
|
||||
self._bg_color_pressed = bg_color_pressed
|
||||
self._icon_color = icon_color
|
||||
self._icon_color_hover = icon_color_hover
|
||||
self._icon_color_pressed = icon_color_pressed
|
||||
self._icon_color_active = icon_color_active
|
||||
self._context_color = context_color
|
||||
self._top_margin = top_margin
|
||||
self._is_active = is_active
|
||||
# Set Parameters
|
||||
self._set_bg_color = bg_color
|
||||
self._set_icon_path = icon_path
|
||||
self._set_icon_color = icon_color
|
||||
self._set_border_radius = radius
|
||||
# Parent
|
||||
self._parent = parent
|
||||
self._app_parent = app_parent
|
||||
|
||||
# TOOLTIP
|
||||
self._tooltip_text = tooltip_text
|
||||
self._tooltip = _ToolTip(
|
||||
app_parent,
|
||||
tooltip_text,
|
||||
dark_one,
|
||||
text_foreground
|
||||
)
|
||||
self._tooltip.hide()
|
||||
|
||||
# SET ACTIVE MENU
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def set_active(self, is_active):
|
||||
self._is_active = is_active
|
||||
self.repaint()
|
||||
|
||||
# RETURN IF IS ACTIVE MENU
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def is_active(self):
|
||||
return self._is_active
|
||||
|
||||
# PAINT EVENT
|
||||
# painting the button and the icon
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def paintEvent(self, event):
|
||||
# PAINTER
|
||||
paint = QPainter()
|
||||
paint.begin(self)
|
||||
paint.setRenderHint(QPainter.RenderHint.Antialiasing)
|
||||
|
||||
if self._is_active:
|
||||
# BRUSH
|
||||
brush = QBrush(QColor(self._context_color))
|
||||
else:
|
||||
# BRUSH
|
||||
brush = QBrush(QColor(self._set_bg_color))
|
||||
|
||||
# CREATE RECTANGLE
|
||||
rect = QRect(0, 0, self.width(), self.height())
|
||||
paint.setPen(Qt.NoPen)
|
||||
paint.setBrush(brush)
|
||||
paint.drawRoundedRect(
|
||||
rect,
|
||||
self._set_border_radius,
|
||||
self._set_border_radius
|
||||
)
|
||||
|
||||
# DRAW ICONS
|
||||
self.icon_paint(paint, self._set_icon_path, rect)
|
||||
|
||||
# END PAINTER
|
||||
paint.end()
|
||||
|
||||
# CHANGE STYLES
|
||||
# Functions with custom styles
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def change_style(self, event):
|
||||
if event == QEvent.Enter:
|
||||
self._set_bg_color = self._bg_color_hover
|
||||
self._set_icon_color = self._icon_color_hover
|
||||
self.repaint()
|
||||
elif event == QEvent.Leave:
|
||||
self._set_bg_color = self._bg_color
|
||||
self._set_icon_color = self._icon_color
|
||||
self.repaint()
|
||||
elif event == QEvent.MouseButtonPress:
|
||||
self._set_bg_color = self._bg_color_pressed
|
||||
self._set_icon_color = self._icon_color_pressed
|
||||
self.repaint()
|
||||
elif event == QEvent.MouseButtonRelease:
|
||||
self._set_bg_color = self._bg_color_hover
|
||||
self._set_icon_color = self._icon_color_hover
|
||||
self.repaint()
|
||||
|
||||
# MOUSE OVER
|
||||
# Event triggered when the mouse is over the BTN
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def enterEvent(self, event):
|
||||
self.change_style(QEvent.Enter)
|
||||
self.move_tooltip()
|
||||
self._tooltip.show()
|
||||
|
||||
# MOUSE LEAVE
|
||||
# Event fired when the mouse leaves the BTN
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def leaveEvent(self, event):
|
||||
self.change_style(QEvent.Leave)
|
||||
self.move_tooltip()
|
||||
self._tooltip.hide()
|
||||
|
||||
# MOUSE PRESS
|
||||
# Event triggered when the left button is pressed
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def mousePressEvent(self, event):
|
||||
if event.button() == Qt.LeftButton:
|
||||
self.change_style(QEvent.MouseButtonPress)
|
||||
# SET FOCUS
|
||||
self.setFocus()
|
||||
# EMIT SIGNAL
|
||||
return self.clicked.emit()
|
||||
|
||||
# MOUSE RELEASED
|
||||
# Event triggered after the mouse button is released
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def mouseReleaseEvent(self, event):
|
||||
if event.button() == Qt.LeftButton:
|
||||
self.change_style(QEvent.MouseButtonRelease)
|
||||
# EMIT SIGNAL
|
||||
return self.released.emit()
|
||||
|
||||
# DRAW ICON WITH COLORS
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def icon_paint(self, qp, image, rect):
|
||||
icon = QPixmap(image)
|
||||
painter = QPainter(icon)
|
||||
painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
|
||||
if self._is_active:
|
||||
painter.fillRect(icon.rect(), self._icon_color_active)
|
||||
else:
|
||||
painter.fillRect(icon.rect(), self._set_icon_color)
|
||||
qp.drawPixmap(
|
||||
(rect.width() - icon.width()) / 2,
|
||||
(rect.height() - icon.height()) / 2,
|
||||
icon
|
||||
)
|
||||
painter.end()
|
||||
|
||||
# SET ICON
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def set_icon(self, icon_path):
|
||||
self._set_icon_path = icon_path
|
||||
self.repaint()
|
||||
|
||||
# MOVE TOOLTIP
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
def move_tooltip(self):
|
||||
# GET MAIN WINDOW PARENT
|
||||
gp = self.mapToGlobal(QPoint(0, 0))
|
||||
|
||||
# SET WIDGET TO GET POSTION
|
||||
# Return absolute position of widget inside app
|
||||
pos = self._parent.mapFromGlobal(gp)
|
||||
|
||||
# FORMAT POSITION
|
||||
# Adjust tooltip position with offset
|
||||
pos_x = (pos.x() - (self._tooltip.width() // 2)) + (self.width() // 2)
|
||||
pos_y = pos.y() - self._top_margin
|
||||
|
||||
# SET POSITION TO WIDGET
|
||||
# Move tooltip position
|
||||
self._tooltip.move(pos_x, pos_y)
|
||||
|
||||
# TOOLTIP
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
class _ToolTip(QLabel):
|
||||
# TOOLTIP / LABEL StyleSheet
|
||||
style_tooltip = """
|
||||
QLabel {{
|
||||
background-color: {_dark_one};
|
||||
color: {_text_foreground};
|
||||
padding-left: 10px;
|
||||
padding-right: 10px;
|
||||
border-radius: 17px;
|
||||
border: 0px solid transparent;
|
||||
font: 800 9pt "Segoe UI";
|
||||
}}
|
||||
"""
|
||||
def __init__(
|
||||
self,
|
||||
parent,
|
||||
tooltip,
|
||||
dark_one,
|
||||
text_foreground
|
||||
):
|
||||
QLabel.__init__(self)
|
||||
|
||||
# LABEL SETUP
|
||||
style = self.style_tooltip.format(
|
||||
_dark_one = dark_one,
|
||||
_text_foreground = text_foreground
|
||||
)
|
||||
self.setObjectName(u"label_tooltip")
|
||||
self.setStyleSheet(style)
|
||||
self.setMinimumHeight(34)
|
||||
self.setParent(parent)
|
||||
self.setText(tooltip)
|
||||
self.adjustSize()
|
||||
|
||||
# SET DROP SHADOW
|
||||
self.shadow = QGraphicsDropShadowEffect(self)
|
||||
self.shadow.setBlurRadius(30)
|
||||
self.shadow.setXOffset(0)
|
||||
self.shadow.setYOffset(0)
|
||||
self.shadow.setColor(QColor(0, 0, 0, 80))
|
||||
self.setGraphicsEffect(self.shadow)
|
||||
@@ -0,0 +1,19 @@
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
#
|
||||
# BY: WANDERSON M.PIMENTA
|
||||
# PROJECT MADE WITH: Qt Designer and PySide6
|
||||
# V: 1.0.0
|
||||
#
|
||||
# This project can be used freely for all uses, as long as they maintain the
|
||||
# respective credits only in the Python scripts, any information in the visual
|
||||
# interface (GUI) can be modified without any implication.
|
||||
#
|
||||
# There are limitations on Qt licenses if you want to use your products
|
||||
# commercially, I recommend reading them on the official website:
|
||||
# https://doc.qt.io/qtforpython/licenses.html
|
||||
#
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
|
||||
# PY PUSH BUTTON
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from . py_push_button import PyPushButton
|
||||
@@ -0,0 +1,71 @@
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
#
|
||||
# BY: WANDERSON M.PIMENTA
|
||||
# PROJECT MADE WITH: Qt Designer and PySide6
|
||||
# V: 1.0.0
|
||||
#
|
||||
# This project can be used freely for all uses, as long as they maintain the
|
||||
# respective credits only in the Python scripts, any information in the visual
|
||||
# interface (GUI) can be modified without any implication.
|
||||
#
|
||||
# There are limitations on Qt licenses if you want to use your products
|
||||
# commercially, I recommend reading them on the official website:
|
||||
# https://doc.qt.io/qtforpython/licenses.html
|
||||
#
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
|
||||
# IMPORT QT CORE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from qt_core import *
|
||||
|
||||
# STYLE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
style = '''
|
||||
QPushButton {{
|
||||
border: none;
|
||||
padding-left: 10px;
|
||||
padding-right: 5px;
|
||||
color: {_color};
|
||||
border-radius: {_radius};
|
||||
background-color: {_bg_color};
|
||||
}}
|
||||
QPushButton:hover {{
|
||||
background-color: {_bg_color_hover};
|
||||
}}
|
||||
QPushButton:pressed {{
|
||||
background-color: {_bg_color_pressed};
|
||||
}}
|
||||
'''
|
||||
|
||||
# PY PUSH BUTTON
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
class PyPushButton(QPushButton):
|
||||
def __init__(
|
||||
self,
|
||||
text,
|
||||
radius,
|
||||
color,
|
||||
bg_color,
|
||||
bg_color_hover,
|
||||
bg_color_pressed,
|
||||
parent = None,
|
||||
):
|
||||
super().__init__()
|
||||
|
||||
# SET PARAMETRES
|
||||
self.setText(text)
|
||||
if parent != None:
|
||||
self.setParent(parent)
|
||||
self.setCursor(Qt.PointingHandCursor)
|
||||
|
||||
# SET STYLESHEET
|
||||
custom_style = style.format(
|
||||
_color = color,
|
||||
_radius = radius,
|
||||
_bg_color = bg_color,
|
||||
_bg_color_hover = bg_color_hover,
|
||||
_bg_color_pressed = bg_color_pressed
|
||||
)
|
||||
self.setStyleSheet(custom_style)
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
#
|
||||
# BY: WANDERSON M.PIMENTA
|
||||
# PROJECT MADE WITH: Qt Designer and PySide6
|
||||
# V: 1.0.0
|
||||
#
|
||||
# This project can be used freely for all uses, as long as they maintain the
|
||||
# respective credits only in the Python scripts, any information in the visual
|
||||
# interface (GUI) can be modified without any implication.
|
||||
#
|
||||
# There are limitations on Qt licenses if you want to use your products
|
||||
# commercially, I recommend reading them on the official website:
|
||||
# https://doc.qt.io/qtforpython/licenses.html
|
||||
#
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
|
||||
# PY SLIDER
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from . py_slider import PySlider
|
||||
@@ -0,0 +1,97 @@
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
#
|
||||
# BY: WANDERSON M.PIMENTA
|
||||
# PROJECT MADE WITH: Qt Designer and PySide6
|
||||
# V: 1.0.0
|
||||
#
|
||||
# This project can be used freely for all uses, as long as they maintain the
|
||||
# respective credits only in the Python scripts, any information in the visual
|
||||
# interface (GUI) can be modified without any implication.
|
||||
#
|
||||
# There are limitations on Qt licenses if you want to use your products
|
||||
# commercially, I recommend reading them on the official website:
|
||||
# https://doc.qt.io/qtforpython/licenses.html
|
||||
#
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
|
||||
# IMPORT QT CORE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from qt_core import *
|
||||
|
||||
style = """
|
||||
/* HORIZONTAL */
|
||||
QSlider {{ margin: {_margin}px; }}
|
||||
QSlider::groove:horizontal {{
|
||||
border-radius: {_bg_radius}px;
|
||||
height: {_bg_size}px;
|
||||
margin: 0px;
|
||||
background-color: {_bg_color};
|
||||
}}
|
||||
QSlider::groove:horizontal:hover {{ background-color: {_bg_color_hover}; }}
|
||||
QSlider::handle:horizontal {{
|
||||
border: none;
|
||||
height: {_handle_size}px;
|
||||
width: {_handle_size}px;
|
||||
margin: {_handle_margin}px;
|
||||
border-radius: {_handle_radius}px;
|
||||
background-color: {_handle_color};
|
||||
}}
|
||||
QSlider::handle:horizontal:hover {{ background-color: {_handle_color_hover}; }}
|
||||
QSlider::handle:horizontal:pressed {{ background-color: {_handle_color_pressed}; }}
|
||||
|
||||
/* VERTICAL */
|
||||
QSlider::groove:vertical {{
|
||||
border-radius: {_bg_radius}px;
|
||||
width: {_bg_size}px;
|
||||
margin: 0px;
|
||||
background-color: {_bg_color};
|
||||
}}
|
||||
QSlider::groove:vertical:hover {{ background-color: {_bg_color_hover}; }}
|
||||
QSlider::handle:vertical {{
|
||||
border: none;
|
||||
height: {_handle_size}px;
|
||||
width: {_handle_size}px;
|
||||
margin: {_handle_margin}px;
|
||||
border-radius: {_handle_radius}px;
|
||||
background-color: {_handle_color};
|
||||
}}
|
||||
QSlider::handle:vertical:hover {{ background-color: {_handle_color_hover}; }}
|
||||
QSlider::handle:vertical:pressed {{ background-color: {_handle_color_pressed}; }}
|
||||
"""
|
||||
|
||||
class PySlider(QSlider):
|
||||
def __init__(
|
||||
self,
|
||||
margin = 0,
|
||||
bg_size = 20,
|
||||
bg_radius = 10,
|
||||
bg_color = "#1b1e23",
|
||||
bg_color_hover = "#1e2229",
|
||||
handle_margin = 2,
|
||||
handle_size = 16,
|
||||
handle_radius = 8,
|
||||
handle_color = "#568af2",
|
||||
handle_color_hover = "#6c99f4",
|
||||
handle_color_pressed = "#3f6fd1"
|
||||
):
|
||||
super(PySlider, self).__init__()
|
||||
|
||||
# FORMAT STYLE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
adjust_style = style.format(
|
||||
_margin = margin,
|
||||
_bg_size = bg_size,
|
||||
_bg_radius = bg_radius,
|
||||
_bg_color = bg_color,
|
||||
_bg_color_hover = bg_color_hover,
|
||||
_handle_margin = handle_margin,
|
||||
_handle_size = handle_size,
|
||||
_handle_radius = handle_radius,
|
||||
_handle_color = handle_color,
|
||||
_handle_color_hover = handle_color_hover,
|
||||
_handle_color_pressed = handle_color_pressed
|
||||
)
|
||||
|
||||
# APPLY CUSTOM STYLE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
self.setStyleSheet(adjust_style)
|
||||
@@ -16,7 +16,6 @@
|
||||
|
||||
# IMPORT QT CORE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from PySide6 import QtSvgWidgets
|
||||
from qt_core import *
|
||||
|
||||
# IMPORT FUNCTIONS
|
||||
|
||||
@@ -103,7 +103,7 @@ class PyTitleButton(QPushButton):
|
||||
|
||||
if self._is_active:
|
||||
# BRUSH
|
||||
brush = QBrush(QColor(self._bg_color_pressed))
|
||||
brush = QBrush(QColor(self._context_color))
|
||||
else:
|
||||
# BRUSH
|
||||
brush = QBrush(QColor(self._set_bg_color))
|
||||
@@ -188,7 +188,7 @@ class PyTitleButton(QPushButton):
|
||||
painter = QPainter(icon)
|
||||
painter.setCompositionMode(QPainter.CompositionMode_SourceIn)
|
||||
if self._is_active:
|
||||
painter.fillRect(icon.rect(), self._context_color)
|
||||
painter.fillRect(icon.rect(), self._icon_color_active)
|
||||
else:
|
||||
painter.fillRect(icon.rect(), self._set_icon_color)
|
||||
qp.drawPixmap(
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
#
|
||||
# BY: WANDERSON M.PIMENTA
|
||||
# PROJECT MADE WITH: Qt Designer and PySide6
|
||||
# V: 1.0.0
|
||||
#
|
||||
# This project can be used freely for all uses, as long as they maintain the
|
||||
# respective credits only in the Python scripts, any information in the visual
|
||||
# interface (GUI) can be modified without any implication.
|
||||
#
|
||||
# There are limitations on Qt licenses if you want to use your products
|
||||
# commercially, I recommend reading them on the official website:
|
||||
# https://doc.qt.io/qtforpython/licenses.html
|
||||
#
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
|
||||
# PY PUSH BUTTON
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from . py_toggle import PyToggle
|
||||
@@ -0,0 +1,89 @@
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
#
|
||||
# BY: WANDERSON M.PIMENTA
|
||||
# PROJECT MADE WITH: Qt Designer and PySide6
|
||||
# V: 1.0.0
|
||||
#
|
||||
# This project can be used freely for all uses, as long as they maintain the
|
||||
# respective credits only in the Python scripts, any information in the visual
|
||||
# interface (GUI) can be modified without any implication.
|
||||
#
|
||||
# There are limitations on Qt licenses if you want to use your products
|
||||
# commercially, I recommend reading them on the official website:
|
||||
# https://doc.qt.io/qtforpython/licenses.html
|
||||
#
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
|
||||
# IMPORT QT CORE
|
||||
# ///////////////////////////////////////////////////////////////
|
||||
from qt_core import *
|
||||
|
||||
class PyToggle(QCheckBox):
|
||||
def __init__(
|
||||
self,
|
||||
width = 50,
|
||||
bg_color = "#777",
|
||||
circle_color = "#DDD",
|
||||
active_color = "#00BCFF",
|
||||
animation_curve = QEasingCurve.OutBounce
|
||||
):
|
||||
QCheckBox.__init__(self)
|
||||
self.setFixedSize(width, 28)
|
||||
self.setCursor(Qt.PointingHandCursor)
|
||||
|
||||
# COLORS
|
||||
self._bg_color = bg_color
|
||||
self._circle_color = circle_color
|
||||
self._active_color = active_color
|
||||
|
||||
self._position = 3
|
||||
self.animation = QPropertyAnimation(self, b"position")
|
||||
self.animation.setEasingCurve(animation_curve)
|
||||
self.animation.setDuration(500)
|
||||
self.stateChanged.connect(self.setup_animation)
|
||||
|
||||
@Property(float)
|
||||
def position(self):
|
||||
return self._position
|
||||
|
||||
@position.setter
|
||||
def position(self, pos):
|
||||
self._position = pos
|
||||
self.update()
|
||||
|
||||
# START STOP ANIMATION
|
||||
def setup_animation(self, value):
|
||||
self.animation.stop()
|
||||
if value:
|
||||
self.animation.setEndValue(self.width() - 26)
|
||||
else:
|
||||
self.animation.setEndValue(4)
|
||||
self.animation.start()
|
||||
print(f"Status: {self.isChecked()}")
|
||||
|
||||
def hitButton(self, pos: QPoint):
|
||||
return self.contentsRect().contains(pos)
|
||||
|
||||
def paintEvent(self, e):
|
||||
p = QPainter(self)
|
||||
p.setRenderHint(QPainter.Antialiasing)
|
||||
p.setFont(QFont("Segoe UI", 9))
|
||||
|
||||
# SET PEN
|
||||
p.setPen(Qt.NoPen)
|
||||
|
||||
# DRAW RECT
|
||||
rect = QRect(0, 0, self.width(), self.height())
|
||||
|
||||
if not self.isChecked():
|
||||
p.setBrush(QColor(self._bg_color))
|
||||
p.drawRoundedRect(0,0,rect.width(), 28, 14, 14)
|
||||
p.setBrush(QColor(self._circle_color))
|
||||
p.drawEllipse(self._position, 3, 22, 22)
|
||||
else:
|
||||
p.setBrush(QColor(self._active_color))
|
||||
p.drawRoundedRect(0,0,rect.width(), 28, 14, 14)
|
||||
p.setBrush(QColor(self._circle_color))
|
||||
p.drawEllipse(self._position, 3, 22, 22)
|
||||
|
||||
p.end()
|
||||
Reference in New Issue
Block a user