PyQt5 QWebEngineView causes blurry/fuzzy scaling issue - python

When a QWebEngineView is added to the window, it causes strange scaling issues across the entire window. This is seen with the latest version of PyQt5 from pip (PyQt5=5.9, Qt5=5.9.1), Python 3.6, and Windows 10. For example:
from PyQt5 import QtGui, QtCore, QtWidgets
from PyQt5 import QtWebEngineWidgets
#
class WebViewer(QtWebEngineWidgets.QWebEngineView):
def __init__(self, parent=None):
super().__init__(parent)
page = QtWebEngineWidgets.QWebEnginePage(self)
self.setPage(page)
self.setUrl(QtCore.QUrl('http://apple.com'))
#
#
if __name__ == '__main__':
appQT = QtWidgets.QApplication([])
#
main_widget = QtWidgets.QWidget(None)
window_layout = QtWidgets.QVBoxLayout(main_widget)
#
window_layout.addWidget(QtWidgets.QTextEdit("1. abc<br/>2. def<br/>3. ghi", main_widget))
####window_layout.addWidget(WebViewer(main_widget))
#
main_widget.show()
appQT.exec_()
#
Results in:
If I uncomment the window_layout.addWidget(WebViewer(main_widget)) line, I get:
The mouse position also does not correspond with what Qt thinks it's clicking on. Is this a bug in Qt5, or is there some dpi/scaling setting I should change? This is also seen with PyQt5.7.1 and PyQt5.8. This doesn't occur with a QWebView in older versions of PyQt5.

Related

Module 'PyQt6.QtWidgets' has no attribute 'QDesktopWidget'

I try to run this code, but it always get this AttributeError, I have searched for many website but there wasn't any answer.
QtWidgets.QDesktopWidget().availableGeometry().center()
AttributeError: module 'PyQt6.QtWidgets' has no attribute 'QDesktopWidget'
My Code:
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def center(self):
qr = Form.frameGeometry()
cp = QtWidgets.QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
I'm using PyQt6 Version 6.1.0, Python 3.9.5
From the docs:
QDesktopWidget and QApplication::desktop() QDesktopWidget was already
deprecated in Qt 5, and has been removed in Qt 6, together with
QApplication::desktop().
QScreen provides equivalent functionality to query for information
about available screens, screen that form a virtual desktop, and
screen geometries.
Use QWidget::setScreen() to create a QWidget on a specific display;
note that this does not move a widget to a screen in a virtual desktop
setup.
Then use:
cp = QtGui.QGuiApplication.primaryScreen().availableGeometry().center()
You can try this
from PyQt6 import QtCore, QtGui, QtWidgets
class Ui_Form(object):
def center(self):
qr=self.frameGeometry()
cp=QtGui.QGuiApplication.primaryScreen().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())

QwebEngineView doesn't show anything

I have created a piece of code that show a simple webpage (a bokeh graph saved in an html file). This code is working in Windows 10 at work, but on macos-mojave, using PyQT5.9, with Python 3.6, the opened window don't show anything, and makes python crash.
Could anyone helps ?
Many thanks
import sys
from PyQt5.QtWidgets import (QApplication)
from PyQt5.QtWebEngineWidgets import QWebEngineView
from PyQt5 import QtCore
class Principale():
def __init__(self):
self.view = QWebEngineView()
self.view.load(QtCore.QUrl("/Users/moncompte/Desktop/essai.html"))
self.view.show()
# Create a custom font
# ---------------------
app = QApplication(sys.argv)
fenetre=Principale()
sys.exit(app.exec_())

QObject.inherits(className) works strange in PyQt5

QObject.inherits(className) does work different in PyQt5 than in PyQt4 and PySide.
from PyQt5 import QtWidgets
#from PySide import QtGui
#from PyQt4 import QtGui
QtWidgets = QtGui
class MyWidget(QtWidgets.QWidget):
pass
app = QtWidgets.QApplication([])
w = MyWidget()
print(w.inherits("MyWidget"))
In PyQt5 it prints False, while in PyQt4 and PySide (uncomment the second or third line and comment the first one) it prints True. Why is that and how to fix it?
I can confirm this behaviour in PyQt-5.7.
It seems to be a bug, because the same problem does not appear in the latest development snapshot (PyQt5_gpl-5.7.1.dev1611251257). The only solution is to wait until PyQt-5.7.1 is released.

Python3 and Qt Designer - Display an image in main window

I'm still new with python and Qt designer. I would like to develop an application where user need to press the 'pushbutton' in order to view the image(from local directory path) on GUI mainwindow.This will keep repeating until complete number of cycle.
Did tried using QLabel and QGraphiscView widget but doesn't work.(probably due to lack of knowledge). Could anyone help me to solve it?
Below is the code:
#!/usr/bin/env python
from __future__ import division
import sys
from PyQt4 import QtCore, QtGui, uic
gui_file = 'image.ui'
Ui_MainWindow, QtBaseClass = uic.loadUiType(gui_file)
class showImage(QtGui.QMainWindow,Ui_MainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
Ui_MainWindow.__init__(self)
self.setupUi(self)
self.get_image_button.clicked.connect(self.getImage)
def getImage(self):
image_path='c:/Users/mohd_faizal4/Desktop/Python/Image/image1.jpg' #path to image file
self.label_image.QPixmap(image_path)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
myWindow = showImage()
myWindow.show()
sys.exit()
app.exec_()
Really appreciate!

Creating a transparent overlay with qt

I've been learning python recently and now I wanted to (try to) create my first real application, a subtitle player for Linux. So far I've been using the Greenfish subtitle player, which is aimed at Windows users and not properly working in Linux.
I wanted to create the application in qt, since I discovered that transparent windows are not possible in tkinter, but if anybody knows a better framework please suggest!
Now before starting I've been researching the web for several hours to discover how to get my application to show over a full screened flash video and it seems like this is not possible. However the aforementioned GF subtitle player manages to do so in Windows, but not in Linux(maybe it's also because it's running through wine).
So my question is it possible to create a transparent application that remains over a fullscreened flash video and if so, could you point me in the right direction?
Thanks in advance.
edit:
here some example code I've been trying. The window produced by this piece of code does not stay above a fullscreened video
import sys
from PyQt4 import QtGui, QtCore
class mymainwindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)
app = QtGui.QApplication(sys.argv)
mywindow = mymainwindow()
mywindow.show()
app.exec_()
mywindow.show()
Update for PyQt5 pip install PyQt5
import sys
from PyQt5 import QtGui, QtCore, uic
from PyQt5 import QtWidgets
from PyQt5.QtWidgets import QMainWindow, QApplication
class MainWindow(QMainWindow):
def __init__(self):
QMainWindow.__init__(self)
self.setWindowFlags(
QtCore.Qt.WindowStaysOnTopHint |
QtCore.Qt.FramelessWindowHint |
QtCore.Qt.X11BypassWindowManagerHint
)
self.setGeometry(
QtWidgets.QStyle.alignedRect(
QtCore.Qt.LeftToRight, QtCore.Qt.AlignCenter,
QtCore.QSize(220, 32),
QtWidgets.qApp.desktop().availableGeometry()
))
def mousePressEvent(self, event):
QtWidgets.qApp.quit()
if __name__ == '__main__':
app = QApplication(sys.argv)
mywindow = MainWindow()
mywindow.show()
app.exec_()
The example code below will create a centred, frameless window that should stay on top of all other windows on Linux (you can click on the window to close it).
import sys
from PyQt4 import QtGui, QtCore
class mymainwindow(QtGui.QMainWindow):
def __init__(self):
QtGui.QMainWindow.__init__(self)
self.setWindowFlags(
QtCore.Qt.WindowStaysOnTopHint |
QtCore.Qt.FramelessWindowHint |
QtCore.Qt.X11BypassWindowManagerHint
)
self.setGeometry(QtGui.QStyle.alignedRect(
QtCore.Qt.LeftToRight, QtCore.Qt.AlignCenter,
QtCore.QSize(220, 32),
QtGui.qApp.desktop().availableGeometry()))
def mousePressEvent(self, event):
QtGui.qApp.quit()
app = QtGui.QApplication(sys.argv)
mywindow = mymainwindow()
mywindow.show()
app.exec_()

Categories

Resources