Skip to content
Snippets Groups Projects

104 preference dialogue gui

Closed Robier Al Kaadi requested to merge 104_Preference_dialogue_GUI into master
1 unresolved thread
Files
11
"""
Qt button for use in preference dialogs, selecting color.
"""
from qtpy.QtCore import Qt, Signal
from qtpy.QtGui import QColor
from qtpy.QtWidgets import QColorDialog, QPushButton
from qtpy.QtWidgets import QPushButton
class ColorButton(QPushButton):
@@ -25,7 +26,7 @@ class ColorButton(QPushButton):
self._color = None
self._default = color
self.pressed.connect(self.pick_color)
# self.pressed.connect(self.pick_color)
# Set the initial/default state.
self.set_color(self._default)
@@ -37,23 +38,27 @@ class ColorButton(QPushButton):
self._color_changed.emit(color)
if self._color:
self.setStyleSheet("background-color: %s;" % self._color)
self.setStyleSheet(f"background-color: {self._color.name()};")
else:
self.setStyleSheet("")
def set_text_color(self, color: QColor):
"""Set text color."""
self.setStyleSheet(f"color: {color.name()};")
@property
def color(self):
"""Current color."""
return self._color
def pick_color(self):
"""Show color-picker dialog to select color."""
dlg = QColorDialog(self)
if self._color:
dlg.setCurrentColor(self._color)
# def pick_color(self):
# """Show color-picker dialog to select color."""
# dlg = QColorDialog(self)
# if self._color:
# dlg.setCurrentColor(self._color)
if dlg.exec_():
self.set_color(dlg.currentColor())
# if dlg.exec_():
# self.set_color(dlg.currentColor())
def mousePressEvent(self, e):
if e.button() == Qt.RightButton:
Loading