@googlefactss · Post #40777 · 12.03.2026 г., 07:01
A group of jellyfish is called a bloom, swarm, or smack. @googlefactss#nowyouknow
Hashtags
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
Пребарај: #nowyouknow
@googlefactss · Post #40777 · 12.03.2026 г., 07:01
A group of jellyfish is called a bloom, swarm, or smack. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #40758 · 07.03.2026 г., 15:04
Jellyfish move in essentially two ways. They take water in their bell and then squirt it out behind them, which creates a jet of water that moves them forward. They also drift on water currents. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #40710 · 27.02.2026 г., 07:04
Horseshoe crabs are not crabs at all. They are not even crustaceans. Instead, they have their own separate class named Merostomata. They have hardly changed since the age of the dinosaurs, and their closest-living relatives are spiders @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #40525 · 11.01.2026 г., 19:02
Blind people smile even though they have never seen anybody else smile. Facial expressions like smiling are largely innate and biological, not just learned through visual imitation and not learned at all. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39979 · 30.10.2025 г., 08:02
Stan is an ancient Persian word meaning “land” or “nation,” and Kazakh means “wanderer,” “adventurer,” or “outlaw.” Therefore, the name Kazakhstan translates as “Land of the Wanderers. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39972 · 29.10.2025 г., 08:48
In terms of absolute size and in proportion to overall body mass, the human penis is longer and thicker than that of any other primate. For instance the average size of the human penis is 8-10 cm when flaccid and 13-15 cm when erect while gorillas, which are the largest primates, have a penis size of approximately 4 cm in length when erect. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39942 · 23.10.2025 г., 07:58
The colors of fire hydrants give a reasonably accurate picture as to how much water flow and pressure they can provide @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39922 · 13.10.2025 г., 12:57
The position dogs assume when they are inviting other pets to play is called a play bow. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39899 · 03.10.2025 г., 22:04
The historical figure who inspired the Santa Claus legend, Saint Nicholas, was born in Patara, Turkey, in the 3rd century A.D. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39888 · 29.09.2025 г., 17:20
Greek philosopher Aristotle (384–322 BC) thought the heart, not the brain, was the center of mental functions, emotions, and intellect. He considered the heart the core of the body's "psychical fire" and the source of its heat, with the brain's main role being to cool the blood. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #39885 · 29.09.2025 г., 13:02
The al-Qarawiyyin Library in Fez, Morocco is the oldest working library in the world. It was founded in 859 CE by Fatima al-Fihriya. @googlefactss#nowyouknow
Hashtags
@googlefactss · Post #40641 · 09.02.2026 г., 15:02
Napoleon I banned fashion dolls because he was nervous they could be used to send secret messages. [Read more] @googlefactss#nowyouknow#history
Hashtags