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

Резултати

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

Пребарај: #karagarga

当前筛选 #karagarga清除筛选
PT资讯频道

@PrivateTrackerNews · Post #773 · 03.08.2019 г., 16:27

#Karagarga (KG) Donations (2019) We have now collected all the funds required. Donations are closed again until 2020. Thank you for your contributions. We've also handed out all donor stars. If we missed you through administrative oversight, please contact ***. 捐款(2019年) 我們現在收集了所需的所有資金。 捐款將再次關閉,直到2020年。 感謝您的貢獻。 我們還發放了所有捐贈明星。 如果我們通過行政監督錯過了您,請聯繫***。

Hashtags

PT风向旗

@Ptfxq · Post #375 · 14.10.2022 г., 22:00

#karagarga#KG The Pot The pot system has been functioning well for more than a decade now, big thanks to all subtitlers and pledgers. Please check if you have claimed any pots. Go to your profile, and after Pot Pledges click on (claimed pots). If you are working on a pot, leave a comment there about progress, and update that post at least every 3 months. If not, cancel your claim. A dormant claim can discourage a potential subtitler. Also, please keep an eye from time to time on pots you started or pledged to (see Pot Pledges in your profile). If good subtitles appeared in the meantime, report that pot with a link to the subs. If you want to subtitle a film for which the pot has been claimed long ago without any news, please contact one of us (corvusalbus, flipflink, cyzs, musiclova). Happy subtitling and viewing!

PT风向旗

@Ptfxq · Post #279 · 28.07.2022 г., 23:35

#KaraGarga#KG#开放捐赠 2022-07-26 Annual Donations (2022) Dear all, we've to collect donations for server / hosting expenses for the year ahead. Please contact stefflbw by pm if you can contribute this year. If you have donated in 2020 or 2021 you can follow the same link / method. In that case please PM stefflbw (with the transaction details) when the donation is complete. If you do not wish to have a donor star activated beside your profile name, please let us know. "What is a suitable amount?" is a frequently asked question. Donations between $10 and $50 have been the most typical. Occasionally members have donated substantially more but the bulk of the annual bill is generally financed by a high number of "smaller" donations. We will post regular updates on the donations total percentage below. Thank you, the KG jungle gym team

PT风向旗

@Ptfxq · Post #926 · 16.08.2025 г., 16:00

#KaraGarga#KG#开放捐赠#慢讯#群友投稿 只是年度捐赠,没有捐入 Dear all, we are commencing our annual donations drive. The funds collected will cover server / hosting expenses from September 2025 to September 2026. How much might a member donate? A typical donation amount in previous years was $10 to $50. A few members have donated substantially more but the bulk of our funds is collected through a higher volume of typical donations. If you have the opportunity to donate in 2025, please PM () for instructions. (If you have donated previously, the instructions have not changed) Much love from The Crow Sanctuary boffins. Target percentage: Aug 3: 17% Aug 4: 28% Aug 5: 37% Aug 6: 47% Aug 7: 56% Aug 8: 69% Aug 9: 74% Aug 10: 77% Aug 11: 80% Aug 12: 85% Aug 14: 87% Aug 15: 90%