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_())
Related
I want to design my QWizardPages in Qt Designer and I want to load them into my Python program with PySide2. Previously I have been using PyQt5 without any problems but making the switch to PySide2 seems harder then expected.
The problem I am facing is that when I am adding a QWizardPage to my QWizard , the page is indeed added to the Wizard, but also an other (empty) page is added. I'm not able to find what I'm doing wrong so I was wondering if someone can have a look.
I have tried to add the pages with both the functions addPage() and setPage(), but they give the same results. What I also noticed is that when I explicitely set the Title of the page with setTitle(), the empty (unwanted) page gets this title, but not the page I designed in Qt Designer.
import os
import sys
from PySide2.QtWidgets import QWizard, QWizardPage, QApplication
from PySide2.QtCore import QFile
from PySide2.QtUiTools import QUiLoader
from enum import Enum
class MyWizard(QWizard):
def __init__(self):
super().__init__()
self.setPage(PageNumbers.page_one.value, PageOne(self))
class PageOne(QWizardPage):
def __init__(self, parent):
super().__init__(parent)
ui_file = os.path.join(__file__, '..', 'pageOne.ui')
file = QFile(ui_file)
file.open(QFile.ReadOnly)
loader = QUiLoader()
loader.load(file, parent)
file.close()
self.setTitle("This is another test Title")
class PageNumbers(Enum):
page_one = 1
if __name__ == '__main__':
app = QApplication(sys.argv)
wizard = MyWizard()
wizard.show()
app.exec_()
What I would expect is to have just one QWizardPage showing up with directly the Finish button. Instead I get two QWizardPages as shown in this image:
Can someone tell me what's going on?
(I get the expected result using PyQt5 with the following code: https://pastebin.com/6W2sx9M1)
The developers of PyQt implement functions to be able to create classes based on the .ui that is not implemented in Qt by default (Qt/C++ uses the MOC to do this work), but in the case of PySide2-Qt for python it does not implement it, only has the QUiLoader class that allows to create a widget based on the .ui unlike PyQt that allows filling a class.
In conclusion there is no equivalent in PySide2 of the loadUi function so you can not implement the same logic. PySide2 is not PyQt5, there are own equivalences since they use the same base but they have implementations, limitations and advantages.
Going to the practical problem, considering that the .ui is next to the .py the solution is the following:
import os
import sys
from PySide2 import QtCore, QtWidgets, QtUiTools
from enum import Enum
class PageNumbers(Enum):
page_one = 0
class MyWizard(QtWidgets.QWizard):
def __init__(self):
super().__init__()
ui_file = os.path.join(os.path.dirname(os.path.abspath(__file__)) ,'PageOne.ui')
page_one = create_widget(ui_file, self)
self.setPage(PageNumbers.page_one.value, page_one)
def create_widget(filename, parent=None):
file = QtCore.QFile(filename)
if not file.open(QtCore.QFile.ReadOnly):
return
loader = QtUiTools.QUiLoader()
widget = loader.load(file, parent)
return widget
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
wizard = MyWizard()
wizard.show()
sys.exit(app.exec_())
I'm begining with Python. I'm developing a simple desktop app to print a control check of motorcycles services. The problem is that the UI not showing the unchecked checkboxes in the table when I run the script
Screenshot with errors in red
Screenshot with cells configuration in Qt5 Designer
The code
import sys
from PyQt5.QtCore import pyqtSlot
from PyQt5.QtWidgets import QApplication, QDialog
from PyQt5.uic import loadUi
class ServiceLabeler(QDialog):
def __init__(self):
super(ServiceLabeler, self).__init__()
loadUi('main.ui', self)
self.btnPrint.clicked.connect(self.printLabel)
#pyqtSlot()
def printLabel(self):
print('Printing ...')
app = QApplication(sys.argv)
widget = ServiceLabeler()
widget.show()
sys.exit(app.exec_())
If you want to see the main.ui code please follow next link to gist
https://gist.github.com/CristalT/0d2e5cc2c684c6dc2b87bd5ec1d7348e
I'm trying to display a PNG image in a Widget using QLabel. I built the Widget using Qt Designer and the label shows the image properly. When I load the .ui into mi .py and execute it, everything shows up well, except for the label. I tried loading the QPixmap manually on the python code, but it didn't work either.
from PyQt5.QtWidgets import (QApplication, QLabel)
from PyQt5.QtGui import (QPixmap)
from PyQt5 import uic
import sys
import os
form = uic.loadUiType('gui/Files/Login.ui')
class LoginWindow(form[0], form[1]):
def __init__(self):
super().__init__()
self.setupUi(self)
self.logoLabel.setPixmap(QPixmap(os.path.abspath(os.path.join(os.path.dirname(__file__), 'logo.png'))))
self.logoLabel.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
win = LoginWindow()
win.show()
app.exec_()
Any idea what am I doing wrong? Any sugestions on how could I display the image other than with QLabel?
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!
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_()