I want to insert video in blue box(ui image) but I don't know how to insert video file.
My code is here.
I don't know how to add video... Just know example that make video player ...
import sys
from PyQt5 import QtWidgets
from PyQt5 import QtGui
from PyQt5 import uic
from PyQt5 import QtCore
from PyQt5.QtCore import QDir, Qt, QUrl, pyqtSlot
from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
from PyQt5.QtMultimediaWidgets import QVideoWidget
from PyQt5.QtWidgets import (QApplication, QFileDialog, QHBoxLayout, QLabel,
QPushButton, QSizePolicy, QSlider, QStyle, QVBoxLayout, QWidget)
dir_audience=''
dir_movie = ''
dir_export = ''
select_emotion = 'happy'
class Form(QtWidgets.QDialog):
def __init__(self, parent=None):
QtWidgets.QDialog.__init__(self, parent)
self.ui = uic.loadUi("highlight_export_form.ui", self)
self.ui.show()
self.ui.load_audience.clicked.connect(self.load_audience_clicked)
self.ui.load_movie.clicked.connect(self.load_movie_clicked)
self.ui.start_recog.clicked.connect(self.start_recog_clicked)
self.ui.radio_happy.toggled.connect(self.on_radio_button_toggled)
self.ui.radio_surprised.toggled.connect(self.on_radio_button_toggled)
def load_audience_clicked(self, event):
dir_audience, _ = QFileDialog.getOpenFileName(self, "Open Audience", QDir.homePath())
self.path_audience.setText(dir_audience)
def load_movie_clicked(self, event):
dir_movie, _ = QFileDialog.getOpenFileName(self, "Open Movie", QDir.homePath())
self.path_movie.setText(dir_movie)
def start_recog_clicked(self, event):
self.check_1.setText("start_recognition")
def on_radio_button_toggled(self):
if self.radio_happy.isChecked():
select_emotion='happy'
self.check_3.setText(select_emotion)
elif self.radio_surprised.isChecked():
select_emotion='surprised'
self.check_3.setText(select_emotion)
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = Form()
sys.exit(app.exec())
Thank you for reading my question.
Qt Designer does not show all the Qt widget, and often we want to add our own widget through Qt, for that there are at least 2 solutions, the first is to create a plugin and load it to Qt Designer, and the other is simpler. promote the widget, the latter is what I will show in this answer.
For this you must make certain minimum changes, I do not know what type of widget is the one you use in the blue box but you must change it to the Widget type that is in the sub-menu of the containers as shown in the following image:
after them you must right click on the widget and select Promote to ..., then a dialogue will appear, in the part of Promoted class name you must place QVideoWidget, and in the part of Header File you must place PyQt5.QtMultimediaWidgets, then press the add button and then Promote:
After that you will be able to use QVideoWidget within your application.
In the following link there is an example
Answer from here was clearer to me:
QWebKit was removed in Qt 5.6. So QWebView is no longer available. Use QWebEngineView as a replacement. In Qt Designer, just add a QWidget to your form and promote it to QWebEngineView (base class: QWidget, header: QWebEngineView). Don't forget to add webenginewidgets to your project file.
Simlar issue: want add QWebEngineView into Qt Designer
for later PySide6 to import and use .ui, exported by Qt Designer
Solution: add QWidget then Promoted to QWebEngineView
Steps
drag a new QWidget into your main ui (window)
right click QWidget -> Promoted to
new popup window, input
Base class Name: QWidget
Promoted class Name: QWebEngineView
Header File: PySide6.QtWebEngineWidgets
== parent class
Global Include: not selected
-> Screenshot
click: Add
click: Promote
Related
I refer to the PySide MDI example in PySide project repository at https://github.com/pyside/Examples/blob/master/examples/mainwindows/mdi/mdi.py. I tried to adopt the same to PySide6 after changing the import reference to from PySide to PySide6. It is working fine in current form.
After making sure that the example works with PySide6, I made following additions:
Implemented a new Widget in Qt Designer (using exe installed in project VE using pip install pyside6) with just one QTextEdit widget on this form. The python code generated by designer is as below:
# -*- coding: utf-8 -*-
################################################################################
## Form generated from reading UI file 'FormWidget01uyjQCJ.ui'
##
## Created by: Qt User Interface Compiler version 6.4.0
##
## WARNING! All changes made in this file will be lost when recompiling UI file!
################################################################################
from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
QMetaObject, QObject, QPoint, QRect,
QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
QFont, QFontDatabase, QGradient, QIcon,
QImage, QKeySequence, QLinearGradient, QPainter,
QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QSizePolicy, QTextEdit, QWidget)
class Ui_FormWidget01(object):
def setupUi(self, FormWidget01):
if not FormWidget01.objectName():
FormWidget01.setObjectName(u"FormWidget01")
FormWidget01.resize(700, 500)
self.textEdit = QTextEdit(FormWidget01)
self.textEdit.setObjectName(u"textEdit")
self.textEdit.setGeometry(QRect(10, 10, 681, 481))
self.retranslateUi(FormWidget01)
QMetaObject.connectSlotsByName(FormWidget01)
# setupUi
def retranslateUi(self, FormWidget01):
FormWidget01.setWindowTitle(QCoreApplication.translate("FormWidget01", u"Form Widget", None))
# retranslateUi
In the mdi.py application, I added the following class for newly generated child on pattern of class MdiChild(QTestEdit) in the above example:
class FormWidget01(Ui_FormWidget01):
def __init__(self):
super(FormWidget01, self).__init__()
self.setAttribute(Qt.WA_DeleteOnClose)
self.isUntitled = True
Finally, I updated class MainWindow(QMainWindow) as below:
Added new function on pattern of newfile(self):
def newFw01(self):
_fw01 = self.createFormWidget01()
_fw01.show()
Added new function on pattern of createMdiChild(self):
def createFormWidget01(self):
fw01 = FormWidget01()
fw01.resize(400, 300)
self.mdiArea.addSubWindow(fw01)
return fw01
And updated createActions(self):
self.newFw01Act = QAction(QIcon(':/images/new.png'), "&New FW01", self,
shortcut=QKeySequence.New, statusTip="Create a new FW",
triggered=self.newFw01)
When I run the updated program and click action for new widget, I get the following error:
File "S:\***\newmdi\mdiapp.py", line 61, in __init__
self.setAttribute(Qt.WA_DeleteOnClose)
AttributeError: 'FormWidget01' object has no attribute 'setAttribute'
At this point, I realized that C++ code generated by the Designer initiate form is like this:
class Ui_FormWidget01
{
public:
QTextEdit *textEdit;
void setupUi(QWidget *FormWidget01)
{
if (FormWidget01->objectName().isEmpty())
FormWidget01->setObjectName("FormWidget01");
FormWidget01->resize(700, 500);
textEdit = new QTextEdit(FormWidget01);
textEdit->setObjectName("textEdit");
...
If I change the python UI class from class Ui_FormWidget01(object): to class Ui_FormWidget01(QWidget):, replacing object with QWidget, the action works but produces a minimized and blank instance of Ui_FormWidget01. There is no QTextEdit visible on it.
I'm not pro at coding and not sure what is going wrong.
In partcular, I need to understand if:
It is possible to create a custom Widget in Qt Designer and use it as MdiChild in Qt MDI application Framework?
If a child widget initialized with QTextEdit works as MDI child but not a child with initialized with object, what could be restrictions on type of an MDI child?
Any clue or explanation is welcome.
everyone.
I want to float a widget inside a layout of a main-window.
the widget is disappered from layout but not displayed on screen
As you can see from following code. I floated two labels 'lbl_title' and 'lbl_icon'
they seems to be floated but not displayed on screen.
Here comes my code.
If you loose commented line, then the lbl_icon and title is removed from layout but not are shown on my screen
from PyQt5.QtCore import QDir, Qt, QUrl
from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer
from PyQt5.QtMultimediaWidgets import QVideoWidget
from PyQt5.QtWidgets import (QApplication, QFileDialog, QHBoxLayout, QLabel,
QPushButton, QSizePolicy, QSlider, QStyle, QVBoxLayout, QWidget)
from PyQt5.QtWidgets import QMainWindow,QWidget, QPushButton, QAction,QGridLayout
from PyQt5.QtGui import QIcon,QPixmap
import sys
from PyQt5.QtCore import *
class CommonLessonItem(QWidget):
def __init__(self,parent):
super(CommonLessonItem,self).__init__(parent)
self.lbl_title = QLabel(self)
self.lbl_description = QLabel(self)
self.lbl_icon = QLabel(self)
self.__initUI()
self.isChild = False
def __initUI(self):
#set layout
self.layout = QGridLayout(self)
self.layout.addWidget(self.lbl_title,0,0,1,19)
self.layout.addWidget(self.lbl_icon,0,19,1,1)
self.layout.addWidget(self.lbl_description,1,0,1,20)
self.lbl_icon.setWindowFlags(Qt.FramelessWindowHint|Qt.Window)
self.lbl_icon.move(100,100)
self.lbl_title.setWindowFlags(Qt.FramelessWindowHint|Qt.Window)
self.lbl_title.move(100,100)
#initialize info
self.setInfo("Title","Description",None)
self.setLayout(self.layout)
def setInfo(self,title,description,iconPath):
self.lbl_title.setText(title)
self.lbl_description.setText(description)
if(iconPath is not None):
self.lbl_icon.setPixmap(QPixmap(iconPath))
def moveEvent(self,event):
super().moveEvent(event)
if __name__ == "__main__":
app = QApplication(sys.argv)
mw = CommonLessonItem(None)
# mw.setSize(10,200)
mw.show()
sys.exit(app.exec_())
I need your help.
Whenever a widget becomes a top level window by setting the parent to None or, like in your case, setting the Window flag (but I wouldn't suggest that approach) show() must be called.
As explained in windowFlags:
Note: This function calls setParent() when changing the flags for a window, causing the widget to be hidden. You must call show() to make the widget visible again..
Add self.lbl_icon.show() and self.lbl_title.show() after changing their window state.
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 used Qt Designer to make two .ui files, one is the Main Window of my application, and the second is a custom widget I made. My idea was to fill a listWidget on my Main application with this custom Widget to display data.
I made this code, which compiles without problem but it does not show the customWidget on the List when it runs
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QWidget, QAction, QTabWidget,QVBoxLayout,QDialog
from PyQt5 import QtCore, QtGui, QtWidgets
from mainwindowReclamo import Ui_MainWindow
from widgetReclamos import Ui_Form
#Custom Widget*
class WidgetReclamo(QWidget, Ui_Form):
"""docstring for ClassName"""
def __init__(self,*args,**kwargs):
QWidget.__init__(self,*args,**kwargs)
self.setupUi(self)
print("I am Alive")
#My Main Program*
class ProgramaReclamos(QMainWindow, Ui_MainWindow):
def __init__(self,*args,**kwargs):
QMainWindow.__init__(self,*args,**kwargs)
self.setupUi(self)
#I create an Item*
Item = QtWidgets.QListWidgetItem(self.listWidget)
#I create a custom widget*
Item_Widget = WidgetReclamo()
#I set the Size from the Item to the same of the widget*
Item.setSizeHint(Item_Widget.sizeHint())
#I add it to the list*
self.listWidget.addItem(Item)
self.listWidget.setItemWidget(Item, Item_Widget)
if __name__ == '__main__':
app = QApplication(sys.argv)
prog = ProgramaReclamos()
prog.show()
sys.exit(app.exec_())
I saw some questions online wich their answer were for PyQt4 and they said something about using a Layout for the Widget, but I don´t understand if I have to make one becouse the widget was made in the .ui file
As EYLLANESC said on the comment:
Change Item.setSizeHint(Item_Widget.sizeHint()) to Item.setSizeHint(Item_Widget.size()) – eyllanesc
Thank you !
How to add image/icon with text in a qlistwidget in pyqt4 python? I want to add an icon with text just like a chat system. thanks
I have tried this right now and it works, supposing you have a file named tick.png in the same folder as this script.
import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import QApplication, QDialog, QListWidgetItem, QListWidget, QIcon
def main():
app = QtGui.QApplication(sys.argv)
window = QDialog()
list = QListWidget( window )
itm = QListWidgetItem( "Tick" );
itm.setIcon(QIcon(r"tick.png"));
list.addItem(itm);
window.show( )
sys.exit(app.exec_())
if __name__ == '__main__':
main()
The chat-like-icon system may be different from this, but right now I don't see a way to have a QListWidgetItem with multiple smileys and text.
You may think of smileys as a particular case of a QListWidgetItem where the text is blank and only the icon is present.
Another solution is using a read-only QTextEdit as chatboard and have the user typing its text + icon + text (etc.) in a separate editable QTextEdit. Then, when he presses the send button, append everything he typed to the read-only QTextEdit.
import sys
from PyQt4 import QtGui, QtCore
from PyQt4.QtGui import QApplication, QDialog, QListWidgetItem, QListWidget, QIcon, QTextEdit, QTextDocumentFragment
def main():
app = QtGui.QApplication(sys.argv)
window = QDialog()
list = QListWidget( window )
textEditor = QTextEdit( window );
textEditor.setReadOnly( True )
tick_icon = QTextDocumentFragment.fromHtml(r"<img src='tick.png'>");
textEditor.insertPlainText ( " ValiumKnight writes: " )
textEditor.textCursor().insertFragment(tick_icon);
textEditor.insertPlainText ( " Hello World " )
textEditor.textCursor().insertFragment(tick_icon);
textEditor.textCursor().insertFragment(tick_icon);
textEditor.textCursor().insertFragment(tick_icon);
window.show( )
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Bye!