add create function
This commit is contained in:
@@ -48,26 +48,52 @@ class MainWindow(QMainWindow):
|
||||
main_layout = QHBoxLayout(central_widget)
|
||||
self.setCentralWidget(central_widget)
|
||||
|
||||
pink_widget = PlaceholderWidget("Pink", "#8A004C" , central_widget)
|
||||
# Main splitter
|
||||
self.view_splitter = self._create_main_content_area()
|
||||
|
||||
# Settings panel
|
||||
self.settings_panel = self._create_settings_panel()
|
||||
|
||||
main_layout.addWidget(self.view_splitter)
|
||||
main_layout.addWidget(self.settings_panel)
|
||||
|
||||
|
||||
|
||||
def _create_main_content_area(self) -> QWidget:
|
||||
# main_panel = QWidget()
|
||||
view_splitter = QSplitter(Qt.Orientation.Horizontal)
|
||||
|
||||
pink_widget = PlaceholderWidget("Pink", "#8A004C")
|
||||
pink_widget.set_text_color("#FFFFFF")
|
||||
|
||||
gray_widget = PlaceholderWidget("Gray", "#808080", central_widget)
|
||||
gray_widget = PlaceholderWidget("Gray", "#808080")
|
||||
gray_widget.set_text_color("#FFFFFF")
|
||||
|
||||
purple_widget = PlaceholderWidget("Purple", "#800080", central_widget)
|
||||
purple_widget = PlaceholderWidget("Purple", "#800080")
|
||||
purple_widget.set_text_color("#FFFFFF")
|
||||
|
||||
green_widget = PlaceholderWidget("Green", "#008000", central_widget)
|
||||
view_splitter.addWidget(pink_widget)
|
||||
view_splitter.addWidget(gray_widget)
|
||||
view_splitter.addWidget(purple_widget)
|
||||
|
||||
view_splitter.setSizes([0, 1, 0])
|
||||
|
||||
return view_splitter
|
||||
|
||||
def _create_settings_panel(self) -> QWidget:
|
||||
settings_panel = QWidget()
|
||||
settings_layout = QVBoxLayout(settings_panel)
|
||||
|
||||
green_widget = PlaceholderWidget("Green", "#008000")
|
||||
green_widget.set_text_color("#FFFFFF")
|
||||
green_widget.setMinimumWidth(400)
|
||||
green_widget.setMinimumHeight(200)
|
||||
|
||||
self.view_splitter = QSplitter(Qt.Orientation.Horizontal)
|
||||
self.view_splitter.addWidget(pink_widget)
|
||||
self.view_splitter.addWidget(gray_widget)
|
||||
self.view_splitter.addWidget(purple_widget)
|
||||
settings_layout.addWidget(QLabel("Ustawienia"))
|
||||
settings_layout.addWidget(green_widget)
|
||||
settings_layout.addStretch()
|
||||
|
||||
self.view_splitter.setSizes([0, 1, 0]) # Początkowy podział na pół
|
||||
main_layout.addWidget(self.view_splitter)
|
||||
main_layout.addWidget(green_widget)
|
||||
return settings_panel
|
||||
|
||||
|
||||
|
||||
|
||||
131
color_custom_filter.py
Normal file
131
color_custom_filter.py
Normal file
@@ -0,0 +1,131 @@
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel,
|
||||
QListView, QLineEdit, QAbstractItemView
|
||||
)
|
||||
from PySide6.QtGui import QPixmap, QColor, QStandardItemModel, QStandardItem
|
||||
from PySide6.QtCore import Qt, QSortFilterProxyModel, QSize
|
||||
import sys
|
||||
|
||||
|
||||
def color_pixmap(color: QColor, size: int = 32) -> QPixmap:
|
||||
pixmap = QPixmap(size, size)
|
||||
pixmap.fill(color)
|
||||
return pixmap
|
||||
|
||||
|
||||
class ColorItemWidget(QWidget):
|
||||
"""Widget do wyświetlania koloru + nazwy + modelu"""
|
||||
def __init__(self, name: str, model: str, color: str):
|
||||
super().__init__()
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(4, 2, 4, 2)
|
||||
|
||||
# ikona koloru
|
||||
icon_label = QLabel()
|
||||
icon_label.setPixmap(color_pixmap(QColor(color)))
|
||||
layout.addWidget(icon_label)
|
||||
|
||||
# tekst: kolor + model (jeden pod drugim)
|
||||
text_layout = QVBoxLayout()
|
||||
name_label = QLabel(name)
|
||||
name_label.setStyleSheet("font-weight: bold;")
|
||||
model_label = QLabel(f"Model: {model}")
|
||||
model_label.setStyleSheet("color: gray; font-size: 10pt;")
|
||||
|
||||
text_layout.addWidget(name_label)
|
||||
text_layout.addWidget(model_label)
|
||||
|
||||
layout.addLayout(text_layout)
|
||||
|
||||
|
||||
class MultiFilterProxy(QSortFilterProxyModel):
|
||||
"""Proxy do filtrowania po nazwie koloru lub modelu"""
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.search_text = ""
|
||||
|
||||
def setSearchText(self, text: str):
|
||||
self.search_text = text.lower()
|
||||
self.invalidateFilter()
|
||||
|
||||
def filterAcceptsRow(self, source_row: int, source_parent) -> bool:
|
||||
model = self.sourceModel()
|
||||
index = model.index(source_row, 0, source_parent)
|
||||
|
||||
color_name = model.data(index, Qt.DisplayRole) # nazwa koloru
|
||||
model_name = model.data(index, Qt.UserRole) # model
|
||||
|
||||
if not self.search_text:
|
||||
return True
|
||||
|
||||
return (
|
||||
self.search_text in color_name.lower()
|
||||
or self.search_text in model_name.lower()
|
||||
)
|
||||
|
||||
|
||||
class CustomListApp(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Customowa lista kolorów z filtrowaniem")
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
|
||||
# Pole filtrowania
|
||||
self.filter_edit = QLineEdit()
|
||||
self.filter_edit.setPlaceholderText("Filtruj po kolorze lub modelu...")
|
||||
self.filter_edit.textChanged.connect(self.apply_filter)
|
||||
layout.addWidget(self.filter_edit)
|
||||
|
||||
# Lista widoku
|
||||
self.list_view = QListView()
|
||||
self.list_view.setSelectionMode(QAbstractItemView.SingleSelection)
|
||||
layout.addWidget(self.list_view)
|
||||
|
||||
# Model danych
|
||||
self.model = QStandardItemModel()
|
||||
|
||||
colors = [
|
||||
("Żółty", "#FFFF00", "r1"),
|
||||
("Zielony", "#00FF00", "r1"),
|
||||
("Różowy", "#FF69B4", "r2"),
|
||||
("Niebieski", "#0000FF", "r2"),
|
||||
("Czerwony", "#FF0000", "r3"),
|
||||
]
|
||||
|
||||
for name, hex_code, model in colors:
|
||||
item = QStandardItem(name) # DisplayRole = nazwa koloru
|
||||
item.setData(model, Qt.UserRole) # UserRole = model
|
||||
item.setData(hex_code, Qt.UserRole + 1) # dodatkowo zapisuję kolor
|
||||
item.setSizeHint(QSize(150, 50)) # wysokość wiersza
|
||||
self.model.appendRow(item)
|
||||
|
||||
# Proxy do filtrowania
|
||||
self.proxy_model = MultiFilterProxy()
|
||||
self.proxy_model.setSourceModel(self.model)
|
||||
|
||||
self.list_view.setModel(self.proxy_model)
|
||||
|
||||
# Wstawiamy custom widgety zamiast domyślnego tekstu
|
||||
self.refresh_widgets()
|
||||
|
||||
def refresh_widgets(self):
|
||||
for row in range(self.proxy_model.rowCount()):
|
||||
index = self.proxy_model.index(row, 0)
|
||||
color_name = index.data(Qt.DisplayRole)
|
||||
model_name = index.data(Qt.UserRole)
|
||||
color_hex = index.data(Qt.UserRole + 1)
|
||||
|
||||
widget = ColorItemWidget(color_name, model_name, color_hex)
|
||||
self.list_view.setIndexWidget(index, widget)
|
||||
|
||||
def apply_filter(self, text: str):
|
||||
self.proxy_model.setSearchText(text)
|
||||
self.refresh_widgets()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = CustomListApp()
|
||||
window.show()
|
||||
sys.exit(app.exec())
|
||||
132
color_custom_filter2.py
Normal file
132
color_custom_filter2.py
Normal file
@@ -0,0 +1,132 @@
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLabel,
|
||||
QListView, QLineEdit, QAbstractItemView
|
||||
)
|
||||
from PySide6.QtGui import QPixmap, QColor, QStandardItemModel, QStandardItem
|
||||
from PySide6.QtCore import Qt, QSortFilterProxyModel, QSize
|
||||
import sys
|
||||
|
||||
|
||||
def color_pixmap(color: QColor, size: int = 32) -> QPixmap:
|
||||
pixmap = QPixmap(size, size)
|
||||
pixmap.fill(color)
|
||||
return pixmap
|
||||
|
||||
|
||||
class ColorItemWidget(QWidget):
|
||||
"""Widget do wyświetlania koloru + nazwy + modelu"""
|
||||
def __init__(self, name: str, model: str, color: str):
|
||||
super().__init__()
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(4, 2, 4, 2)
|
||||
|
||||
# ikona koloru
|
||||
icon_label = QLabel()
|
||||
icon_label.setPixmap(color_pixmap(QColor(color)))
|
||||
layout.addWidget(icon_label)
|
||||
|
||||
# tekst: kolor + model (jeden pod drugim)
|
||||
text_layout = QVBoxLayout()
|
||||
name_label = QLabel(name)
|
||||
name_label.setStyleSheet("font-weight: bold;")
|
||||
model_label = QLabel(f"Model: {model}")
|
||||
model_label.setStyleSheet("color: gray; font-size: 10pt;")
|
||||
|
||||
text_layout.addWidget(name_label)
|
||||
text_layout.addWidget(model_label)
|
||||
|
||||
layout.addLayout(text_layout)
|
||||
|
||||
|
||||
class MultiFilterProxy(QSortFilterProxyModel):
|
||||
"""Proxy do filtrowania po nazwie koloru lub modelu"""
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.search_text = ""
|
||||
|
||||
def setSearchText(self, text: str):
|
||||
self.search_text = text.lower()
|
||||
self.invalidateFilter()
|
||||
|
||||
def filterAcceptsRow(self, source_row: int, source_parent) -> bool:
|
||||
model = self.sourceModel()
|
||||
index = model.index(source_row, 0, source_parent)
|
||||
|
||||
color_name = model.data(index, Qt.UserRole + 2) # nazwa
|
||||
model_name = model.data(index, Qt.UserRole) # model
|
||||
|
||||
if not self.search_text:
|
||||
return True
|
||||
|
||||
return (
|
||||
self.search_text in color_name.lower()
|
||||
or self.search_text in model_name.lower()
|
||||
)
|
||||
|
||||
|
||||
class CustomListApp(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Customowa lista kolorów z filtrowaniem")
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
|
||||
# Pole filtrowania
|
||||
self.filter_edit = QLineEdit()
|
||||
self.filter_edit.setPlaceholderText("Filtruj po kolorze lub modelu...")
|
||||
self.filter_edit.textChanged.connect(self.apply_filter)
|
||||
layout.addWidget(self.filter_edit)
|
||||
|
||||
# Lista widoku
|
||||
self.list_view = QListView()
|
||||
self.list_view.setSelectionMode(QAbstractItemView.SingleSelection)
|
||||
layout.addWidget(self.list_view)
|
||||
|
||||
# Model danych
|
||||
self.model = QStandardItemModel()
|
||||
|
||||
colors = [
|
||||
("Żółty", "#FFFF00", "r1"),
|
||||
("Zielony", "#00FF00", "r1"),
|
||||
("Różowy", "#FF69B4", "r2"),
|
||||
("Niebieski", "#0000FF", "r2"),
|
||||
("Czerwony", "#FF0000", "r3"),
|
||||
]
|
||||
|
||||
for name, hex_code, model in colors:
|
||||
item = QStandardItem()
|
||||
item.setData(model, Qt.UserRole) # model
|
||||
item.setData(hex_code, Qt.UserRole+1) # kolor
|
||||
item.setData(name, Qt.UserRole+2) # nazwa
|
||||
item.setSizeHint(QSize(150, 50)) # wysokość wiersza
|
||||
self.model.appendRow(item)
|
||||
|
||||
# Proxy do filtrowania
|
||||
self.proxy_model = MultiFilterProxy()
|
||||
self.proxy_model.setSourceModel(self.model)
|
||||
|
||||
self.list_view.setModel(self.proxy_model)
|
||||
|
||||
# Wstawiamy custom widgety zamiast domyślnego tekstu
|
||||
self.refresh_widgets()
|
||||
|
||||
def refresh_widgets(self):
|
||||
for row in range(self.proxy_model.rowCount()):
|
||||
index = self.proxy_model.index(row, 0)
|
||||
color_name = index.data(Qt.UserRole+2)
|
||||
model_name = index.data(Qt.UserRole)
|
||||
color_hex = index.data(Qt.UserRole+1)
|
||||
|
||||
widget = ColorItemWidget(color_name, model_name, color_hex)
|
||||
self.list_view.setIndexWidget(index, widget)
|
||||
|
||||
def apply_filter(self, text: str):
|
||||
self.proxy_model.setSearchText(text)
|
||||
self.refresh_widgets()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = CustomListApp()
|
||||
window.show()
|
||||
sys.exit(app.exec())
|
||||
155
color_custom_filter_combobox.py
Normal file
155
color_custom_filter_combobox.py
Normal file
@@ -0,0 +1,155 @@
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication, QWidget, QVBoxLayout, QHBoxLayout, QLineEdit, QListView,
|
||||
QAbstractItemView, QComboBox, QLabel
|
||||
)
|
||||
from PySide6.QtGui import QPixmap, QColor, QStandardItemModel, QStandardItem
|
||||
from PySide6.QtCore import Qt, QSortFilterProxyModel, QSize
|
||||
import sys
|
||||
|
||||
|
||||
def color_pixmap(color: QColor, size: int = 32) -> QPixmap:
|
||||
pixmap = QPixmap(size, size)
|
||||
pixmap.fill(color)
|
||||
return pixmap
|
||||
|
||||
|
||||
class ColorItemWidget(QWidget):
|
||||
"""Widget do wyświetlania koloru + nazwy + modelu"""
|
||||
def __init__(self, name: str, model: str, color: str):
|
||||
super().__init__()
|
||||
layout = QHBoxLayout(self)
|
||||
layout.setContentsMargins(4, 2, 4, 2)
|
||||
|
||||
# ikona koloru
|
||||
icon_label = QLabel()
|
||||
icon_label.setPixmap(color_pixmap(QColor(color)))
|
||||
layout.addWidget(icon_label)
|
||||
|
||||
# tekst: kolor + model (jeden pod drugim)
|
||||
text_layout = QVBoxLayout()
|
||||
name_label = QLabel(name)
|
||||
name_label.setStyleSheet("font-weight: bold;")
|
||||
model_label = QLabel(f"Model: {model}")
|
||||
model_label.setStyleSheet("color: gray; font-size: 10pt;")
|
||||
|
||||
text_layout.addWidget(name_label)
|
||||
text_layout.addWidget(model_label)
|
||||
|
||||
layout.addLayout(text_layout)
|
||||
|
||||
|
||||
class MultiFilterProxy(QSortFilterProxyModel):
|
||||
"""Proxy do filtrowania po nazwie koloru i modelu"""
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.search_text = ""
|
||||
self.selected_model = "all"
|
||||
|
||||
def setSearchText(self, text: str):
|
||||
self.search_text = text.lower()
|
||||
self.invalidateFilter()
|
||||
|
||||
def setSelectedModel(self, model: str):
|
||||
self.selected_model = model.lower()
|
||||
self.invalidateFilter()
|
||||
|
||||
def filterAcceptsRow(self, source_row: int, source_parent) -> bool:
|
||||
model = self.sourceModel()
|
||||
index = model.index(source_row, 0, source_parent)
|
||||
|
||||
color_name = model.data(index, Qt.UserRole + 2) # nazwa
|
||||
model_name = model.data(index, Qt.UserRole) # model
|
||||
|
||||
# filtr po modelu
|
||||
if self.selected_model != "all" and model_name.lower() != self.selected_model:
|
||||
return False
|
||||
|
||||
# filtr po nazwie
|
||||
if self.search_text and self.search_text not in color_name.lower():
|
||||
return False
|
||||
|
||||
return True
|
||||
|
||||
|
||||
class CustomListApp(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Lista kolorów z filtrem po nazwie i modelu")
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
|
||||
# Górny panel z filtrami
|
||||
filter_layout = QHBoxLayout()
|
||||
|
||||
self.filter_edit = QLineEdit()
|
||||
self.filter_edit.setPlaceholderText("Szukaj po nazwie koloru...")
|
||||
self.filter_edit.textChanged.connect(self.apply_text_filter)
|
||||
filter_layout.addWidget(QLabel("Nazwa:"))
|
||||
filter_layout.addWidget(self.filter_edit)
|
||||
|
||||
self.model_combo = QComboBox()
|
||||
self.model_combo.addItems(["all", "r1", "r2", "r3"])
|
||||
self.model_combo.currentTextChanged.connect(self.apply_model_filter)
|
||||
filter_layout.addWidget(QLabel("Model:"))
|
||||
filter_layout.addWidget(self.model_combo)
|
||||
|
||||
layout.addLayout(filter_layout)
|
||||
|
||||
# Lista widoku
|
||||
self.list_view = QListView()
|
||||
self.list_view.setSelectionMode(QAbstractItemView.SingleSelection)
|
||||
layout.addWidget(self.list_view)
|
||||
|
||||
# Model danych
|
||||
self.model = QStandardItemModel()
|
||||
|
||||
colors = [
|
||||
("Żółty", "#FFFF00", "r1"),
|
||||
("Zielony", "#00FF00", "r1"),
|
||||
("Różowy", "#FF69B4", "r2"),
|
||||
("Niebieski", "#0000FF", "r2"),
|
||||
("Czerwony", "#FF0000", "r3"),
|
||||
]
|
||||
|
||||
for name, hex_code, model in colors:
|
||||
item = QStandardItem()
|
||||
item.setData(model, Qt.UserRole) # model
|
||||
item.setData(hex_code, Qt.UserRole+1) # kolor
|
||||
item.setData(name, Qt.UserRole+2) # nazwa
|
||||
item.setSizeHint(QSize(150, 50)) # wysokość wiersza
|
||||
self.model.appendRow(item)
|
||||
|
||||
# Proxy do filtrowania
|
||||
self.proxy_model = MultiFilterProxy()
|
||||
self.proxy_model.setSourceModel(self.model)
|
||||
|
||||
self.list_view.setModel(self.proxy_model)
|
||||
|
||||
# Wstawiamy custom widgety
|
||||
self.refresh_widgets()
|
||||
|
||||
def refresh_widgets(self):
|
||||
for row in range(self.proxy_model.rowCount()):
|
||||
index = self.proxy_model.index(row, 0)
|
||||
color_name = index.data(Qt.UserRole+2)
|
||||
model_name = index.data(Qt.UserRole)
|
||||
color_hex = index.data(Qt.UserRole+1)
|
||||
|
||||
widget = ColorItemWidget(color_name, model_name, color_hex)
|
||||
self.list_view.setIndexWidget(index, widget)
|
||||
|
||||
def apply_text_filter(self, text: str):
|
||||
self.proxy_model.setSearchText(text)
|
||||
self.refresh_widgets()
|
||||
|
||||
def apply_model_filter(self, model: str):
|
||||
self.proxy_model.setSelectedModel(model)
|
||||
self.refresh_widgets()
|
||||
self.model_combo.hidePopup()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = CustomListApp()
|
||||
window.show()
|
||||
sys.exit(app.exec())
|
||||
29
color_list.py
Normal file
29
color_list.py
Normal file
@@ -0,0 +1,29 @@
|
||||
from PySide6.QtWidgets import QApplication, QListWidget, QListWidgetItem
|
||||
from PySide6.QtGui import QPixmap, QIcon, QColor
|
||||
import sys
|
||||
|
||||
def color_icon(color: QColor, size: int = 32) -> QIcon:
|
||||
"""Tworzy ikonę z prostokątem w danym kolorze."""
|
||||
pixmap = QPixmap(size, size)
|
||||
pixmap.fill(color)
|
||||
return QIcon(pixmap)
|
||||
|
||||
app = QApplication(sys.argv)
|
||||
|
||||
list_widget = QListWidget()
|
||||
list_widget.setIconSize(list_widget.iconSize().expandedTo(list_widget.iconSize()))
|
||||
|
||||
# Lista kolorów (nazwa, hex)
|
||||
colors = [
|
||||
("Czerwony", "#FF0000"),
|
||||
("Zielony", "#00FF00"),
|
||||
("Niebieski", "#0000FF"),
|
||||
("Żółty", "#FFFF00"),
|
||||
]
|
||||
|
||||
for name, hex_code in colors:
|
||||
item = QListWidgetItem(color_icon(QColor(hex_code)), name)
|
||||
list_widget.addItem(item)
|
||||
|
||||
list_widget.show()
|
||||
sys.exit(app.exec())
|
||||
58
color_list_filter.py
Normal file
58
color_list_filter.py
Normal file
@@ -0,0 +1,58 @@
|
||||
from PySide6.QtWidgets import (
|
||||
QApplication, QWidget, QVBoxLayout, QListWidget, QListWidgetItem,
|
||||
QLineEdit, QLabel
|
||||
)
|
||||
from PySide6.QtGui import QPixmap, QIcon, QColor
|
||||
import sys
|
||||
|
||||
|
||||
def color_icon(color: QColor, size: int = 24) -> QIcon:
|
||||
pixmap = QPixmap(size, size)
|
||||
pixmap.fill(color)
|
||||
return QIcon(pixmap)
|
||||
|
||||
|
||||
class ColorFilterApp(QWidget):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.setWindowTitle("Lista kolorów z filtrowaniem")
|
||||
|
||||
layout = QVBoxLayout(self)
|
||||
|
||||
self.filter_edit = QLineEdit()
|
||||
self.filter_edit.setPlaceholderText("Filtruj po modelu...")
|
||||
self.filter_edit.textChanged.connect(self.apply_filter)
|
||||
layout.addWidget(QLabel("Filtruj:"))
|
||||
layout.addWidget(self.filter_edit)
|
||||
|
||||
self.list_widget = QListWidget()
|
||||
layout.addWidget(self.list_widget)
|
||||
|
||||
# Dane: kolor + model
|
||||
self.colors = [
|
||||
("Żółty", "#FFFF00", "r1"),
|
||||
("Zielony", "#00FF00", "r1"),
|
||||
("Różowy", "#FF69B4", "r2"),
|
||||
("Niebieski", "#0000FF", "r2"),
|
||||
("Czerwony", "#FF0000", "r3"),
|
||||
]
|
||||
|
||||
# Dodajemy elementy
|
||||
for name, hex_code, model in self.colors:
|
||||
item = QListWidgetItem(color_icon(QColor(hex_code)), f"{name} (model: {model})")
|
||||
item.setData(256, model) # zapisz model jako dodatkowe dane
|
||||
self.list_widget.addItem(item)
|
||||
|
||||
def apply_filter(self, text: str):
|
||||
"""Filtruj elementy po modelu"""
|
||||
for i in range(self.list_widget.count()):
|
||||
item = self.list_widget.item(i)
|
||||
model = item.data(256) # pobierz zapisany model
|
||||
item.setHidden(text.lower() not in model.lower())
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
app = QApplication(sys.argv)
|
||||
window = ColorFilterApp()
|
||||
window.show()
|
||||
sys.exit(app.exec())
|
||||
Reference in New Issue
Block a user