TGTGInsighttelegram intelligenceLIVE / telegram public index
← Python Заметки

TGINSIGHT SIMILAR POSTS

Најди сличен содржај

Изворен канал @pythonotes · Post #381 · 23 окт.

Установить свойства виджета в PySide можно не только через соответствующие методы и конструктор класса. Можно их изменять с помощью метода setProperty по имени. btn = QPushButton("Click Me") btn.setProperty("flat", True) Это аналогично вызову btn.setFlat(True) Если указать несуществующее свойство, то оно просто создается btn.setProperty("btnType", "super") Получить его значение можно методом .property(name) btn_type = btn.property("btnType") Когда это может быть полезно? ▫️Можно просто хранить какие то данные в виджете и потом их доставать обратно widget = QWidget() widget.setProperty('my_data', 123) print(widget.property('my_data')) ▫️ Назначая эти свойства разным виджетам можно потом отличить виджеты во время итераци по ним. Например, найти все кнопки со свойством my_data="superbtn". Но ведь вместо кастомного свойства можно использовать objectName, будет тот же результат. Да, но y ObjectName есть ограничение - только строки. ▫️ Если нам потребуется не просто поиск а, например, сортировка по числу, то свойства позволяют нам это сделать. Поддерживается любой тип данных widget.setProperty('my_data', {'Key': 'value'}) widget.setProperty('order', 1) all_widgets.sort(key=w: w.property('order')) Но ведь Python позволяет всё вышеперечисленное сделать простым созданием атрибута у объекта widget.order = 1 widget.my_data = 123 Да, но я думаю что не надо объяснять почему не стоит так делать. К тому же, если у виджета нет свойства то метод .property(name) вернет None, а отсутствующий атрибут выбросит исключение. ▫️ Действительно полезное применение кастомным свойствам - контроль стилей. Здесь атрибутами не обойтись, нужны именно свойства. Дело в том, что в селекторах стилей можно указывать конкретные свойства виджетов на которые следует назначать стиль. Просто запустите этот код from PySide2.QtWidgets import * if __name__ == "__main__": app = QApplication([]) widget = QWidget(minimumWidth=300) layout = QVBoxLayout(widget) btn1 = QPushButton("Action 1") btn2 = QPushButton("Action 2") btn3 = QPushButton("Action 3", flat=True) layout.addWidget(btn1) layout.addWidget(btn2) layout.addWidget(btn3) # добавим кастомное свойство одной кнопке btn1.setProperty("btnType", "super") # добавляем стили widget.setStyleSheet( """ QPushButton[btnType="super"] { background-color: yellow; color: red; } QPushButton[flat="true"] { color: yellow; } """ ) widget.show() app.exec_() С помощью селектора мы избирательно назначили стили на конкретные кнопки. Как получить список всех кастомный свойств? Функция получения списка кастомных свойств отличается от получения дефолтных. def print_widget_dyn_properties(widget): for prop_name in widget.dynamicPropertyNames(): property_name = prop_name.data().decode() property_value = widget.property(property_name) print(f"{property_name}: {property_value}") #tricks#qt

Hashtags

Резултати

Пронајдени 31 слични објави

Пребарај: #paste

当前筛选 #paste清除筛选
Dishes.Cooking.Food

@cookingdish · Post #936 · 28.08.2025 г., 13:01

🍂Pumpkin Pasta!🍝 Ingredients: * 2 Pumpkins * 1 head Garlic * 1 tsp dry Oregano * 1 tbsp Paprika * 4 sprigs fresh Thyme * 1 sprig Sage * Olive oil * Pasta (of your choice) * Salt & Pepper, to taste * 1 Shallot * 1/3 cup White dry wine * 1 cup heavy Cream * 100 g. Parmigiano Reggiano #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #477 · 13.08.2024 г., 13:01

Caramelized Onion Pasta Ingredients: Oven: *300 g shallots *300 g vegan cream cheese *60 ml maple syrup *200 g smoked tofu *salt and pepper *Oil as desired Aside from that: *350g pasta *200 g dried tomatoes *1 bunch of fresh wild garlic *60 ml pasta water #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #475 · 11.08.2024 г., 13:02

Rice Noodle Spring Salad Ingredients: *1 carrot *100 g fresh red cabbage *1/2 cucumber *1/2 red onion *1 mango *250 g rice noodles Peanut sauce: *2 cm ginger *2 cloves of garlic *200 g peanut butter *20 ml sesame oil *50 ml maple syrup *50 ml soy sauce *150ml water Toppings: Chili flakes Coriander, mint peanuts #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #471 · 07.08.2024 г., 15:03

Roasted Vegetables Pasta Ingredients: *2 peppers *12 cherry tomatoes *150 g mushrooms *3 onions *6 cloves of garlic *1/2 zucchini Marinade: *Oil as desired *1 tsp chili *1 tsp salt *1 tbsp paprika *1 tbsp oregano *1 tbsp thyme *Price pepper Sauce: *200 g vegan cream cheese *82 tbsp tomato paste *2 handfuls of fresh basil *2 tbsp pasta water *1 tbsp balsamic vinegar Topping: *Pine nuts, roasted *Parmesan, vegan *Basil, fresh #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #459 · 28.07.2024 г., 15:48

You Need To Taste This Green Goddess Salad With Watermelon & Pasta Ingredients: *200 grams of watermelon *100 grams of cucumber *200 grams of pasta Dressing: *80 grams of spinach *1/2 bunch basil *1 clove of garlic *1/2 onion *50 grams of peas *40ml oil *25ml water *1 tbsp vinegar *1 tsp salt *40 grams of walnuts *juice of a lemon *1 tbsp yeast flakes *pinch of pepper toppings: Walnuts, Basil, Chili Flakes #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #406 · 12.06.2024 г., 13:01

Creamy Salmon Pasta Ingredients: *2 steaks of Salmon *50g. Butter *1 Shallot Onion *2 Fresh garlic cloves *1 1/2 Cup Cream. Heavy cream/whipping cream. *Fresh Dill or Parsley *1/2 TspLemon zest *Dry white Wine *Salt and black pepper. *Pasta Penne #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #397 · 07.06.2024 г., 12:59

Pasta Alla Vodka with Pancetta🧀 Ingredients: *350g. Rigatoni pasta (Can be replaced with penne pasta) *2 Tbsp Olive oil *150g. diced Pancetta *2 Shallot onion, finely chopped *3 Garlic cloves, finely chopped *1/2 Tsp Red-Chilli flakes *1/2 Tsp dried Oregano *1/2 cup Vodka *1 cup Tomato sauce *1/4 cup Tomato paste with basil pesto *2 cup Heavy cream *1/4 cup Parmesan cheese, plus more for serving *1 tablespoon roughly chopped fresh Basil *2 tablespoons roughly chopped Italian Parsley #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #349 · 13.04.2024 г., 16:59

PASTA WITH SHALLOTS & HERBS!🍝🌱 Ingredients: * Pasta * 1 cup Heavy cream * ¾ cup Parmesan cheese * 2 Shallots * 4 cloves Garlic * ¼ cup White wine * 4 tbsp Olive oil * 1 tbsp Butter * Fresh parsley * Chives * Salt/Pepper #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #341 · 06.04.2024 г., 12:04

ROASTED RED PEPPER PASTA! 🌶️ Ingredients: * 400 g. Giant Fusilli Pasta * 4 Red Bell Peppers * 2 Shallot onion * 1 head Garlic * Olive oil * 1 cup Heavy Cream * Red chili flakes * Italian herbs * 1 tbsp Tomato paste * 1 tbsp Butter * Salt/Pepper #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #339 · 03.04.2024 г., 12:05

AVOCADO SPINACH PASTA! ✨🥑 Ingredients: * 2 cloves Garlic * 1 Avocado * 130 g. Spinach * 50 g. Roasted pine nuts * Olive oil * Lemon juice * 100 ml. Water * Vegan parmesan * Cherry tomatoes * Salt/Pepper #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #335 · 31.03.2024 г., 14:19

ALFREDO RIGATONI! ✨ Ingredients: * Rigatoni * Shallot * Mushrooms * Garlic * Olive oil * White wine * Butter * Salt/Pepper * Cream * Fresh parsley * Parmesan cheese #paste @dishes

Hashtags

Dishes.Cooking.Food

@cookingdish · Post #318 · 19.03.2024 г., 15:00

KALE PASTA! 🍝 Ingredients: * 250 g. Pasta * 3 handfuls Kale * 1 Red onion * 3 cloves Garlic * Olive oil * 2 tbsp Tomato paste * Lemon juice * 400 ml. Vegan cream * Salt/Pepper * Vegan parmesan * Chili flakes #paste @dishes

Hashtags

ПретходнаСтраница 1 од 3Следна