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

Резултати

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

Пребарај: #jptv

当前筛选 #jptv清除筛选
PT风向旗

@Ptfxq · Post #513 · 19.12.2023 г., 11:00

#JPTV.club #综合公告 End of the year 2023 Hey kids, I hope you are well! Thank you for spending time on our silly little site! How about joining our staff team here at JPTVclub? We are always looking for more people to help out on staff. If you are interested in joining our team, send Benkei a message on the site or Matrix. Currently we need staff to help out moderating torrents, applications and the forums, but we are always looking for other new staff members that can help the site run smoothly. If you think you have something to offer, send Benkei a message. We look forward to hearing from you. ---------------------------- Have you seen JPTVclubTV yet? The official JPTVclub IPTV servers are up and running!! The links have been up on Matrix for a couple days now (Have you joined our Matrix server yet?). You can download the channel list using your site credentials from here: Currently, 6 channels at 360p with a limit of 2 streams per user. That all may change in the future. If you have any ideas, let me know. Our servers are weak, your performance will vary. Let me know if you think there is are channels we should add or take away. I am interested in what you think!! If you have never used IPTV before, VLC or a browser plugin is a great place to start. Ask in the forums or Matrix if you have any questions or problems. If users are interested in the IPTV service, it will stay around for a while, but if there is no interest, it will go away early next year. --------------------------- New User Classes!!! Finally the new donor user classes are here! “Donor” = H&R immunity + Freeleech USD $10 per month “VIP” = H&R immunity + Freeleech + JPTV Recorder + Fileokiba USD $30 per month The VIP user class is limited to 10 members currently. “JPTV Recorder” allows recording and streaming of Japanese TV. “JPTV Recorder” is in beta and will often not work as expected. “Fileokiba” is https and WebDAV access to all bot recordings of the last month or so. To sign up for Donor or VIP user class, send Benkei a DM for more information. If you are not interested in a monthly donation but would still like to contribute, we gladly accept one-time donations as well. I really appreciate anyone that is kind enough to donate. The site is expensive. And without your help, its days are numbered. 🙁

PT风向旗

@Ptfxq · Post #831 · 31.12.2024 г., 16:00

祝各位 Pter 们元旦快乐!按照惯例,以下为各站在元旦期间的活动汇总,欢迎群友投稿补充: #1PTba #站点免费 至 01-02 09:00:00 #Audiences#观众 #站点免费 12.31 22:00:00 至 01.01 23:59:59 #官种免费 01.02 00:00:00 至 01.03 23:59:59 #BTSchool#学校 #开放注册 即日起至 01.01 #站点免费 01.02 至 01.04 #BakaBT #站点免费 至 1 月 13 日 00:00 CET #CarPT#车站 #站点免费 01.01 至 01.03 #CinemaTIK#TIK #站点免费 7 天 #CHD#岛 #站点免费 站免 1 天 #HHanclub#HHan#憨憨 #开放邀请 01-01 VIP+开放邀请 #HiTpt#百川PT#百川 #站点免费 01-01 00:00 至 01-03 #kufei#库非 #站点免费 12-31 00:00 至 01-02 00:00 #GPW#greatposterwall#海豹 开放答题进站活动 12-29 00:00 至 01-05 23:59 #JPTV#JPTVCLUB #站点免费 剩余 7 天+ #LemonHD#柠檬 音乐区限时全员开放 全区免费下载 音乐入场券限时五折,仅需 40,5000 魔力 发种活动,详情请至站内查看 #Mteam#馒头 #站点免费 01-03 00:00 开始站免 3 天 #NicePT#老师 #开放邀请 每人 10 枚临时邀请 01.01 至 01.03 有效,禁止公开平台发邀 #OB#Ourbits#我堡 #站点免费 至 01-02 00:00 #Piggo#猪猪 #站点免费 01.01 00:00:00 至 01.01 23:59:59 限时红包雨活动,元旦节当天每逢整点,站点页面将开启红包雨,争抢点击红包可获得魔力、上传量、限时 VIP 等奖励 勋章商店限时上架 2025 元旦勋章 #TTG #站点免费 至 01-04 21:59 #U2 #站点免费 01-01 一天 #wintersakura #站点免费 12-25 00:00:00 至 01-10 00:00:00