Is there an alternative in Qt5 python3 to the following code :
https://askubuntu.com/questions/153549/how-to-detect-a-computers-physical-screen-size-in-gtk
from gi.repository import Gdk
s = Gdk.Screen.get_default()
print(s.get_width(), s.get_height())
PyQt is significantly older than PySide and, partially due to that, has a larger community and is usually ahead when it comes to adopting new developments. It is mainly developed by Riverbank Computing Limited and distributed under GPL v3 and a commercial license.
The latest iteration of PyQt is v5. 11.3. It fully supports Qt 5.11.
There are so many options provided by Python to develop GUI application and PyQt5 is one of them. PyQt5 is cross-platform GUI toolkit, a set of python bindings for Qt v5. One can develop an interactive desktop application with so much ease because of the tools and simplicity provided by this library.
You can get the primary screen from the QApplication
, which returns a QScreen object giving access to many useful properties:
import sys
from PyQt5 import QtWidgets
app = QtWidgets.QApplication(sys.argv)
screen = app.primaryScreen()
print('Screen: %s' % screen.name())
size = screen.size()
print('Size: %d x %d' % (size.width(), size.height()))
rect = screen.availableGeometry()
print('Available: %d x %d' % (rect.width(), rect.height()))
Note that the primaryScreen
method is static, so if you've already created an instance of QApplication elsewhere in your application, can easily get a QScreen object later on like this:
screen = QApplication.primaryScreen()
from PyQt5.QtWidgets import QApplication, QWidget
self.desktop = QApplication.desktop()
self.screenRect = self.desktop.screenGeometry()
self.height = self.screenRect.height()
self.width = self.screenRect.width()
You can see here - https://www.programmersought.com/article/58831562998/
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With