@QuietWorld · Post #7554 · 12.08.2020 г., 11:41
the tone and the way you talk about something, makes a difference. #fact@quietworld🍃
Hashtags
TGINSIGHT SIMILAR POSTS
Изворен канал @pythonotes · Post #380 · 21 окт.
Регулярно приходится писать и ревьюить код, где используется PySide2-6. Заметил, что в подавляющем большинстве случаев настройка создаваемых базовых виджетов происходит через методы. Думаю, всем знаком такой способ. Простой пример с кнопкой: button = QPushButton("Click Me") button.setMinimumWidth(300) button.setFlat(True) button.setStyleSheet("font-size: 20pt") button.setToolTip("Super Button") button.clicked.connect(lambda: print("Button clicked")) Но есть и альтернативный способ - настройка через свойства. Это просто ключевые аргументы конструктора класса. Хоть они и не указаны в документации как аргументы, но они есть) Этот код делает тоже самое но с помощью Property button = QPushButton( "Click Me", minimumWidth=300, flat=True, styleSheet="font-size: 20pt", toolTip="Super Button", clicked=lambda: print("Button clicked"), ) Где это может быть полезно ▫️ Это выглядит более аккуратно и коротко, уже повод использовать ▫️ Может использоваться в заполнении лейаута, когда нам не нужно никакое другое взаимодействие с виджетом и поэтому сохранять его в переменную не требуется. Например, лейбл или кнопка. widget = QWidget(minimumWidth=400) layout = QHBoxLayout(widget) layout.addWidget(QLabel("Button >", alignment=Qt.AlignRight)) layout.addWidget(QPushButton("Click Me", clicked=lambda: print("Button clicked"))) widget.show() Либо так widget = QWidget(minimumWidth=400) layout = QHBoxLayout(widget) for wd in ( QLabel("Button >", alignment=Qt.AlignRight), QPushButton("Click Me", clicked=lambda: ...) ): layout.addWidget(wd) widget.show() ▫️ Можно хранить настройки в каком-то конфиге или генерировать на лету, после чего передавать как kwargs. kwargs = {"text": "Hello " * 30, "wordWrap": True} my_label = QLabel(**kwargs) Как получить полный список доступных свойств? Эта функция распечатает в терминал все свойства виджета и их текущие значения def print_widget_properties(widget): meta_object = widget.metaObject() for i in range(meta_object.propertyCount()): property_ = meta_object.property(i) property_name = property_.name() property_value = property_.read(widget) print(f"{property_name}: {property_value}") #tricks#qt
Пребарај: #fact
@QuietWorld · Post #7554 · 12.08.2020 г., 11:41
the tone and the way you talk about something, makes a difference. #fact@quietworld🍃
Hashtags
@QuietWorld · Post #6420 · 30.04.2019 г., 17:54
true 💯💯 #fact@quietworld🍃
Hashtags
@PlanetRong · Post #3482 · 11.02.2020 г., 17:18
#fact 我能听到 19500Hz 的声音。 20000Hz 有微弱听觉,戴上耳机能感觉到。 18000Hz 以下有较敏锐的听觉。 (我能确定听到的不是因为各种原因导致的杂音,高频正弦波的听感还是很好区分的
Hashtags
@whysoserioushmmm · Post #3470 · 26.04.2020 г., 11:30
Celebrities need us more than we need them. #fact
Hashtags
@whysoserioushmmm · Post #3274 · 20.03.2020 г., 09:57
Karma has no menu. You get served what you deserve. #fact @whysoserioushmmm
Hashtags
@whysoserioushmmm · Post #3266 · 19.03.2020 г., 06:40
Even though hand sanitizer kills 99.9% of germs, only 0.1% of germs actually make us sick #fact @whysoserioushmmm
Hashtags
@whysoserioushmmm · Post #3191 · 02.03.2020 г., 12:35
Bullet proof vests, fire escapes, windshield wipers and laser printers were all invented by women. #fact @whysoserioushmmm
Hashtags
@astronomic · Post #3032 · 10.10.2022 г., 17:13
Ceres accounts for one third of the mass in the asteroid belt. #Fact
Hashtags
@PlanetRong · Post #2997 · 07.01.2020 г., 17:28
#fact 两天总睡眠时间不足4h
Hashtags
@whysoserioushmmm · Post #2914 · 31.01.2020 г., 15:54
Vitamin D Doesn't come from the sun🌞; it comes from our skin. Sunlight☀️ is the factor that converts cholesterol in our skin to vitamin D3. #fact @whysoserioushmmm
Hashtags
@whysoserioushmmm · Post #2913 · 31.01.2020 г., 15:54
Mobile phones have 18 times more bacteria than Toilet🚽 Handles. #fact @whysoserioushmmm
Hashtags
@whysoserioushmmm · Post #2911 · 31.01.2020 г., 15:54
A 2014 study estimates that the human body consists of 39 trillion bacteria & 30 trillion human cells. #fact @whysoserioushmmm
Hashtags