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

Резултати

Пронајдени 1,598 слични објави

Пребарај: #cute

当前筛选 #cute清除筛选
Midjourney Prompts Daily

@neirodrive · Post #8619 · 30.05.2025 г., 08:21

A Daredevil helmet from Marvel's Daredevil series, floating in the air against a dark red and black background with a hint of rain, in a cinematic, poster-style composition, with "MARVEL" written on it --ar 91:114 --profile hbgntj7 --s 750 --v 7 by mido314 #cute 📣Midjourney prompts

Hashtags

Midjourney Prompts Daily

@neirodrive · Post #8539 · 16.04.2025 г., 06:19

Side view of 3D walking boy wearing glossy chrome metal down jacket and black cargo pants, wearing purple futuristic sneakers, 45 degree angle walking pose, full body, minimalism, simple curves, clay material skin, impassive face side view, cartoon style, 2D illustration, solid light grey background --v 7 #cute 📣Midjourney prompts

Hashtags

Midjourney Prompts Daily

@neirodrive · Post #8525 · 15.04.2025 г., 17:48

retro inspired design of a white bear head shaped portable pocked sized gaming console, the screen say "GAME OVER", minimalist design, soft shapes curves and edges, matte plastic material, flying in the air, against gradient light orange background, 3D render, cute 3D icon --v 7 #cute 📣Midjourney prompts

Hashtags

Midjourney Prompts Daily

@neirodrive · Post #8508 · 14.04.2025 г., 09:22

funny cute old man with a kind face, in home clothes and slippers, free pose, in a cozy home environment, primitive and funny --c 10 --s 300 --v 7 by gaelle764 #cute 📣 Midjourney prompts

Hashtags

Midjourney Prompts Daily

@neirodrive · Post #8498 · 10.04.2025 г., 07:51

A black british shorthair cat wearing sunglasses and an elegant floral scarf is holding a cup of coffee, wearing a dark brown knitted sweater, against a purple background. This is a high-resolution, hyper-realistic, and ultra-detailed photorealistic image, 3/4 front side view --v 7 - Photograph of an anthropomorphic British Shorthair cat dressed in sunglasses and a winter coat, holding a coffee cup, wearing a floral scarf around its neck, against a solid color background with a pink color theme, in the style of fashion photography, high resolution, hyper-realistic --v 7 #cute 📣 Midjourney prompts

Hashtags

Midjourney Prompts Daily

@neirodrive · Post #8406 · 24.03.2025 г., 07:10

A close-up shot of a Korean Shorthair cat wearing stylish round glasses, sitting in front of a laptop, its paws actively typing on the keyboard with a serious and focused expression, the soft glow of the screen reflecting in its eyes, in a dimly lit home office with a warm and cozy ambiance, shot with a Canon EOS R5, 85mm f/1.2 lens, warm and neutral tones --c 12 --ar 3:4 --style raw --sref 3022677299 --profile jmupltd --sw 100 --s 1000 --v 6.1 by jeremycl #cute 📣Midjourney prompts

Hashtags

Midjourney Prompts Daily

@neirodrive · Post #8094 · 29.12.2024 г., 09:02

🎄С наступающим! Pure red gradient background [Long haired white rabbit baby], perched in the palm of a person, black ears, black eyes, white fur, a little fluffy, wearing a red crown on his head, his face painted with pink powder blusher, holding a big red Christmas gift box and Christmas tree in his hand, hanging a small bell on the Christmas tree, too cute, too charged. This photo is very realistic and accurately captures the subtle features of the long haired white rabbit --ar 3:4 --v 6.1 by lily_martin7149 #cute 📣Midjourney prompts

Hashtags

Midjourney Prompts Daily

@neirodrive · Post #7800 · 18.10.2024 г., 13:38

The cutest miniature donkey you've ever seen, with white hair, big eyes and long eyelashes, is undoubtedly the cutest and most charming, being held in the arms of its owner --ar 9:16 --v 6.1 by yidexiaonongchang #cute 📣 Midjourney prompts

Hashtags

Midjourney Prompts Daily

@neirodrive · Post #7621 · 26.09.2024 г., 09:10

create a minimalistic 3D character illustration of a happy fit woman stretching, plain white background, cute 3D icon --v 6.1 - create a minimalistic 3D character illustration of a happy woman standing and admiring her earrings, plain white background, cute 3D icon --v 6.1 by mkzdesign_09334 #cute 📣Midjourney prompts

Hashtags

123•••100•••133134
ПретходнаСтраница 1 од 134Следна