Регулярно приходится писать и ревьюить код, где используется 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
📰 FFmpeg Introduces Vulkan-Accelerated 360 Degree Video Conversion
Beyond the capabilities of just the Vulkan Video API, the FFmpeg multimedia library has made interesting Vulkan-accelerated adaptations using compute shaders. With Vulkan compute they've implemented Apple ProRes video acceleration, FFV1 decode, and other features. The newest Vulkan feature now in place for FFmpeg is 360 degree video conversion...
🔗 Source: https://www.phoronix.com/news/FFmpeg-360-Degree-Vulkan
#ffmpeg
📰 FFmpeg 8.1 Released With Experimental xHE-AAC MPS212, More Vulkan Acceleration
FFmpeg 8.1 is out today as the newest stable release of this widely-used, open-source multimedia library...
🔗 Source: https://www.phoronix.com/news/FFmpeg-8.1-Released
#opensource#ffmpeg
📰 Gentoo-Based Redcore Linux Hardened 2601 Released with Kernel 6.19
Redcore Linux Hardened 2601 Vulpecula has been released, featuring Linux kernel 6.19, FFmpeg 8, and updates to the Sisyphus package manager.
🔗 Source: https://linuxiac.com/gentoo-based-redcore-linux-hardened-2601-released-with-kernel-6-19/
#ffmpeg#kernel#linux
Кстати! Я всем советую попробовать HandBrake — программу для ужатия видео.
Это графический интерфейс для мощной библиотеки ffmpeg, которая заточена на перегонку видео в разные форматы.
Я в основном использую для уменьшения размера файлов, чтобы телеграм проигрывал их без звука автоматически
Тут подробнее писал как это работает
Анимацию постом выше я просто закинул и без изменения настроек перегнал из mpg в mp4. Размер изменился с 4.5мб до 300кб
А для тизера «Коротких вопросов» нажав две кнопки, смог уменьшить файл со 167 мб до (!) 3 мб. За счет уменьшения размера сторон с 4к до 720p.
На мобиле разницы скорее всего не будет видно, а вовлечение в просмотр повысится — сплошная польза!
Работает на всех платформах, в том числе на маке и линуксе!
🎤Ссылки на утро — второй канал
⏲Ускорить YouTube за звезду (VPN за 2₽)
#ToolReview@cogload#ffmpeg@cogload#telegram@cogload
🔖 The creator of ffmpeg Fabrice Bellard(1) is truly a genius and has created so many amazing software that have been an amazing benefit to the world. | Hacker News #pinboard#pantheon#ffmpeg#person
Yeah definitely. If programming genius had a unit it should be called the bellard.
One 10x programmer = a 1/10th Bellard?
100x 工程师,可以放在万神殿了
https://news.ycombinator.com/item?id=25487711
This is Probably the Best Video Downloader App (And it is Free and Open Source) | itsFOSS
VidBee allows you to download videos from YouTube, Facebook, X, Instagram, etc. In fact, it supports over 1,800 websites.
It is built on top of popular command line tools like yt-dlp and #ffmpeg. For the interface, it uses the Electron framework. I understand that some people dislike Electron framework as it runs a web browser underneath, but the 'advantage' of this framework is that you get the same interface in all the operating systems. At least, it's an advantage for the developers as they don't have to build the interface separately for #Linux, #Windows and #macOS.
The source code for VidBee is available on its GitHub repository.
#VidBee - Free Open Source Video Downloader
https://vidbee.org/