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

Резултати

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

Пребарај: #functionality

当前筛选 #functionality清除筛选
BAGEVM 广播站

@bagenotice · Post #128 · 04.06.2025 г., 11:09

#功能通知 很高兴的通知大家,目前我们已经上线了新的自动续费的功能,已关闭传统的余额自动扣除方案,这样只有开启了自动续费按钮的机器才会自动扣除余额进行续费,其他机器将不会在出现忘记取消扣除余额的动作,欢迎大家进行体验反馈BUG。 #Functionality Notice We are very happy to inform you that we have launched a new automatic renewal function and have closed the traditional automatic balance deduction plan. In this way, only machines with the automatic renewal button turned on will automatically deduct the balance for renewal. Other machines will not forget to cancel the balance deduction action. Everyone is welcome to experience and feedback BUGs.

BAGEVM 广播站

@bagenotice · Post #119 · 14.04.2025 г., 10:33

#功能通知 很高兴的通知大家,目前我们已经上线了流量自动重置的功能,在流量重置页面你可以点击针对单个实例,设置在流量使用完毕后在账号余额充足的情况下,系统会自动帮您扣除余额重置流量 https://www.bagevm.com/index.php?m=trafficreset #Functionality Notice We are pleased to inform you that we have now launched the traffic automatic reset function, in the traffic reset page you can click on a single instance, set in the traffic after the use of sufficient account balance, the system will automatically help you deduct the balance to reset the traffic https://www.bagevm.com/index.php?m= trafficreset

BLC Market - mini-app BulCoin

@bulcoin_blc · Post #287 · 09.03.2026 г., 11:30

How task creation will work in BLC Market We continue to showcase the interface of the future BLC Market app. Today - one of the key elements of the platform: task creation. A user will be able to post a task in just a few steps: • choose a category • describe the task • add photo or video - if needed • set the price, choosing the coin for payment • publish the task After publication, the task becomes available to performers who can offer their services. All transactions will take place within the platform using BLC. In the following posts, we will show: • what the performer's profile will look like • how arbitration will occur through the Association of Arbitration Courts • how the transaction system works Early access to the interface testing is given to Pioneers participants. #Tasks#BLC_Market#functionality FAQ | BUY