I am adding a gif to my QMainWindow. I want the size of my window to match exactly the size of QMovie but my QMovie is truncated at the first place and even if use resize on that, its still not showing fully.
Here is the code :
from typing import Text
from PyQt5 import QtWidgets as qtw
from PyQt5 import QtCore as qtc
from PyQt5 import QtGui as qtg
import sys
class MainWindow(qtw.QDialog):
def __init__(self, *arg, **kwargs):
super().__init__(*arg, **kwargs)
self.centralwidget = qtw.QWidget(self)
self.centralwidget.setObjectName("centralwidget")
self.label = qtw.QLabel(self.centralwidget)
movie = qtg.QMovie('mic_listen2.gif')
movie.setScaledSize(qtc.QSize(50,50))
self.label.setMovie(movie)
movie.start()
self.show()
if __name__ == '__main__':
app = qtw.QApplication(sys.argv)
w = MainWindow()
sys.exit(app.exec_())
Here is the gif
https://media.giphy.com/media/QGMXK7Byy6MSXKVRlc/giphy.gif
Here is my output
You must set both the minimum size of the label and that of the widget.
#!/usr/bin/env python3
from typing import Text
from PyQt5 import QtWidgets
from PyQt5 import QtCore
from PyQt5 import QtGui
import sys
class MainWindow(QtWidgets.QDialog):
def __init__(self, movsize=50, *arg, **kwargs):
super().__init__(*arg, **kwargs)
self.centralwidget = QtWidgets.QWidget(self)
self.centralwidget.setObjectName("centralwidget")
self.label = QtWidgets.QLabel(self.centralwidget)
self.movie = QtGui.QMovie("giphy.gif")
self.movie.setScaledSize(QtCore.QSize(movsize, movsize))
self.movie.start()
self.label.setMovie(self.movie)
self.label.setMinimumSize(self.movie.scaledSize())
self.centralwidget.setMinimumSize(self.label.minimumSize())
# Uncomment to force the window to take the size of the movie.
# self.setMaximumSize(self.movie.scaledSize())
self.show()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w2 = MainWindow(movsize=160)
w3 = MainWindow(movsize=500)
sys.exit(app.exec_())
Related
I'm trying to get a background image to my mainwindow but i can't get it to work properly.
import sys
from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QLabel
from PyQt5.QtGui import QIcon
from PyQt5 import QtWidgets
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtSvg import *
from PyQt5.QtWidgets import *
from abc import abstractmethod
class App(QMainWindow):
def __init__(self, parent=None):
super(App, self).__init__(parent=parent)
self.title = 'Title'
self.left = 500
self.top = 500
self.width = 440
self.height = 280
self.initUI()
def initUI(self):
self.setWindowTitle(self.title)
self.setGeometry(self.left, self.top, self.width, self.height)
# ...
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = App()
#view = TableScene(ex)
ex.show()
sys.exit(app.exec_())
I've tried different kinds of methods but none of them works as it should.
I found the following code as a solution from another topic but it just gives me a black background and the rest of the widgets get laggy.
oImage = QImage("table.png")
sImage = oImage.scaled(QSize(440, 280))
palette = QPalette()
palette.setBrush(QPalette.Window, QBrush(sImage))
self.setPalette(palette)
I don't know if the whole window gets laggy or what really happens but the picture below is a screenshot of a part of the window using the code above, and as you can see it gets all black and the slider shows all the previous position it has been on, sort of laggy anyways.
I've also tried the setStyleSheet but I don't know if it's my syntax that's wrong or if it's a faulty way of doing it. Does anyone know a way of doing it correctly?
EDIT
This is my current window:
This is the picture I'm trying to implement as a background to my current window, the picture called "table.png" :
This is a visualization of what I'm trying to do, and this is made in paint since I don't know how to do it correctly:
And this is what I get if i use the code from the other topic:
One of the possible reasons why a black background appears is that QImage is null. And a QImage is null because the image is invalid or because the image path is incorrect. In this case I think it is the second case since the OP uses a relative path that is prone to errors. The solution is to build the absolute path using the script information such as its location:
import os
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
class App(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(App, self).__init__(parent=parent)
self.initUI()
def initUI(self):
self.setWindowTitle("Title")
self.setGeometry(500, 500, 440, 280)
oImage = QtGui.QImage(os.path.join(CURRENT_DIR, "table.png"))
sImage = oImage.scaled(QtCore.QSize(440, 280))
palette = QtGui.QPalette()
palette.setBrush(QtGui.QPalette.Window, QtGui.QBrush(sImage))
self.setPalette(palette)
pushbutton = QtWidgets.QPushButton("test", self)
pushbutton.move(100, 100)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
ex = App()
ex.show()
sys.exit(app.exec_())
Note: The image provided by the OP has extension .jpg but the one indicated by code is .png, maybe "imgur" has changed the extension.
Note: If the window is resized manually, the following behavior will be observed:
So for this there are 2 possible solutions depending on the developer's criteria:
Set a fixed size: self.setFixedSize(440, 280)
Adapt the image to the size of the window:
import os
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
class App(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(App, self).__init__(parent=parent)
self.initUI()
def initUI(self):
self.setWindowTitle("Title")
self.setGeometry(500, 500, 440, 280)
pushbutton = QtWidgets.QPushButton("test", self)
pushbutton.move(100, 100)
self.oImage = QtGui.QImage(os.path.join(CURRENT_DIR, "table.png"))
# or QPixmap
# self.oPixmap = QtGui.QPixmap(os.path.join(CURRENT_DIR, "table.png"))
def paintEvent(self, event):
painter = QtGui.QPainter(self)
painter.drawImage(self.rect(), self.oImage)
# or QPixmap
# painter.drawPixmap(self.rect(), self.oPixmap)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
ex = App()
ex.show()
sys.exit(app.exec_())
or
import os
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))
class App(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(App, self).__init__(parent=parent)
self.initUI()
def initUI(self):
self.setWindowTitle("Title")
self.setGeometry(500, 500, 440, 280)
pushbutton = QtWidgets.QPushButton("test", self)
pushbutton.move(100, 100)
self.setStyleSheet(
"""
QMainWindow{
border-image: url(%s) 0 0 0 0 stretch stretch
}
"""
% os.path.join(CURRENT_DIR, "table.png")
)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
ex = App()
ex.show()
sys.exit(app.exec_())
I am trying to figure out how I can create a drop down list (currently using QComoboBox), with a few items, and when I hover my mouse/click on one of the options, it shows a sub list, containing a few more options.
I tried to search online but couldn't find anything that I could use.
Here an example of what I want to achieve (sorry for terrible quality, but I think it makes it clear what my goal is..)
Does any one have an idea of how to make a sub list inside a list?
Edit
After trying #eyllanesc suggestion I still having a problem:
I am using two files: one file that contains all the objects like buttons and such, and the other one that contains some functions and basically makes the GUI functional.
I defined this on my first file
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(751, 650)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.menuBtn=QtWidgets.QPushButton(self.centralwidget)
self.menuBtn.setGeometry(QtCore.QRect(100, 220, 100, 100))
self.productMenu=QtWidgets.QMenu(self.centralwidget)
self.menu1=self.productMenu.addMenu("options")
self.menu1.addAction("option 1")
self.menu2=self.productMenu.addMenu("option 2")
self.menu2.addAction("option 2a")
self.menu2.addAction("option 2b")
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Test"))
self.menuBtn.setText(_translate("MainWindow", "Menu"))
And on the second file (the functional) I wrote this:
from PyQt5 import QtWidgets, QtCore, QtGui
from stackTest import Ui_MainWindow
import sys
class ApplicationWindow(QtWidgets.QMainWindow):
def __init__(self):
super(ApplicationWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.productMenu.triggered.connect(lambda action: self.ui.menuBtn.setText(action.text("Hello!")))
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
application = ApplicationWindow()
application.show()
sys.exit(app.exec_())
When I run the code, I can see the button, but when I click it nothing happens.
How can I make it run so when I push the button I'll get the menu.
One possible solution is to use a button (QPushButton, QToolButton, etc.) and establish a QMenu as I show below:
import sys
from PyQt5 import QtCore, QtWidgets
def create_menu(d, menu):
if isinstance(d, list):
for e in d:
create_menu(e, menu)
elif isinstance(d, dict):
for k, v in d.items():
sub_menu = QtWidgets.QMenu(k, menu)
menu.addMenu(sub_menu)
create_menu(v, sub_menu)
else:
action = menu.addAction(d)
action.setIconVisibleInMenu(False)
class Widget(QtWidgets.QWidget):
def __init__(self, parent=None):
super().__init__(parent)
d = ["1", "2", "3", {"4": ["5", "6", {"7": ["8", "9"]}]}, {"10": "11"}]
menu = QtWidgets.QMenu(self)
create_menu(d, menu)
button = QtWidgets.QPushButton()
button.setMenu(menu)
menu.triggered.connect(lambda action: button.setText(action.text()))
lay = QtWidgets.QHBoxLayout(self)
lay.addWidget(button)
lay.addStretch()
self.resize(640, 480)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = Widget()
w.show()
sys.exit(app.exec_())
The code provided by the OP must add the QMenu to the QPushButton:
import sys
from PyQt5 import QtWidgets, QtCore, QtGui
from stackTest import Ui_MainWindow
class ApplicationWindow(QtWidgets.QMainWindow):
def __init__(self):
super(ApplicationWindow, self).__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.menuBtn.setMenu(self.ui.productMenu)
self.ui.productMenu.triggered.connect(
lambda action: self.ui.menuBtn.setText(action.text())
)
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
application = ApplicationWindow()
application.show()
sys.exit(app.exec_())
I have 2 windows: MainWindow and a normal window, I have a button in MainWindow that open the second window and I have a button in the second window, I want when clicked the button in the second window close the MainWindow. The two windows are in separate class and files.
This is the MainWindow
from select_company_controller import SelectCompany
from views.main_window_view import MainWindowForm
from PySide2 import QtWidgets, QtCore, QtGui
import sys
class MainWindow(QtWidgets.QMainWindow, MainWindowForm):
def __init__(self):
super(MainWindow, self).__init__()
self.setupUi(self)
self.button.clicked.connect(self.open_select_company_window)
def open_select_company_window(self):
self.window = SelectCompany()
self.window.show()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
window.showMaximized()
sys.exit(app.exec_())
And this is the second window
from PySide2 import QtWidgets, QtCore, QtGui
from views.select_company_view import SelectCompanyForm
class SelectCompany(QtWidgets.QWidget, SelectCompanyForm):
def __init__(self):
super(SelectCompany, self).__init__()
self.setupUi(self)
self.button.clicked.connect(close_main_window)
def close_main_window(self):
pass
Try it:
main.py
import sys
#from PySide2 import QtWidgets, QtCore, QtGui
from PyQt5 import QtWidgets, QtCore, QtGui
from select_company_controller import SelectCompany
#from views.main_window_view import MainWindowForm
class MainWindow(QtWidgets.QMainWindow): #, MainWindowForm):
def __init__(self):
super(MainWindow, self).__init__()
# self.setupUi(self)
self.setWindowTitle('Main Window')
centralWidget = QtWidgets.QWidget()
self.setCentralWidget(centralWidget)
button = QtWidgets.QPushButton('Open SelectCompany')
button.clicked.connect(self.open_select_company_window)
grid = QtWidgets.QGridLayout(centralWidget)
grid.addWidget(button)
def open_select_company_window(self):
self.window = SelectCompany(self)
self.window.show()
if __name__ == '__main__':
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.show() #showMaximized()
sys.exit(app.exec_())
select_company_controller.py
#from PySide2 import QtWidgets, QtCore, QtGui
from PyQt5 import QtWidgets, QtCore, QtGui
#from views.select_company_view import SelectCompanyForm
class SelectCompany(QtWidgets.QMainWindow): #QWidget, SelectCompanyForm):
def __init__(self, parent=None):
super(SelectCompany, self).__init__(parent)
self.parent = parent
self.setWindowTitle('SelectCompany')
centralWidget = QtWidgets.QWidget()
self.setCentralWidget(centralWidget)
button = QtWidgets.QPushButton('Close MainWindow')
button.clicked.connect(self.close_main_window)
grid = QtWidgets.QGridLayout(centralWidget)
grid.addWidget(button)
def close_main_window(self):
self.parent.hide()
Update
#from PySide2 import QtWidgets, QtCore, QtGui
from PyQt5 import QtWidgets, QtCore, QtGui
#from views.select_company_view import SelectCompanyForm
class SelectCompany(QtWidgets.QWidget): #, SelectCompanyForm): # <--- QWidget
def __init__(self, parent=None):
super(SelectCompany, self).__init__(parent)
self.parent = parent
self.setWindowFlags(QtCore.Qt.Window | QtCore.Qt.WindowStaysOnTopHint) # <---
self.setWindowTitle('SelectCompany')
button = QtWidgets.QPushButton('Close MainWindow')
button.clicked.connect(self.close_main_window)
grid = QtWidgets.QGridLayout(self)
grid.addWidget(button)
def close_main_window(self):
self.parent.hide()
Trying to animate a line growing from nothing to a (0,0) to (200, 200) line with PyQt5 and using QPropertyAnimation. I already read a lot of documentation about Qt and tried several samples, but I just cannot get this to work. This is the code I have now:
from PyQt5 import QtCore
from PyQt5.QtWidgets import QApplication, QWidget, QLabel
from PyQt5.QtGui import QPainter, QPixmap, QPainterPath
from PyQt5.QtCore import QObject, QPointF, QPropertyAnimation, pyqtProperty
from PyQt5.QtCore import QLineF
import sys
class Sample(QWidget):
l1 = QLineF(QPointF(), QPointF())
def __init__(self):
super().__init__()
self.initView()
self.initAnimation()
def initView(self):
self.show()
def initAnimation(self):
self.anim = QPropertyAnimation(self.l1, b'geometry')
self.anim.setDuration(7000)
self.anim.setStartValue(QPointF(0, 0))
self.anim.setEndValue(QPointF(200, 200))
self.anim.start()
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = Sample()
sys.exit(app.exec_())
Not posting all previous attemps, each one fails with a different error. I got a fade out animation on a widget to work, and a picture following a path, but I can seem to make a simple line drawing work. I was hoping to achieve something like this:
Codepen example
Qt documentation is huge and it seems there are several ways to achieve this, painter and timer, animation, variant animation, but I am not very familiar with C++ and the translation to Python is not always easy. Also samples are not that easy to find.
Am I missing something obvious?
Thanks!
For the record, this is what I achieved so far but as soon as I un-comment the QPropertyAnimation creation, app does not launch. Anyway I was still far from the result in the accepted answer.
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *
import sys
class MyLine(QGraphicsLineItem, QObject):
def __init__(self):
super().__init__()
def _set_start(self, point):
self.setLine(point.x(), point.y(), self.line().p2().x(), self.line().p2().y())
def _set_end(self, point):
self.setLine(self.line().p1().x(), self.line().p1().y(), point.x(), point.y())
start = pyqtProperty(QPointF, fset=_set_start)
end = pyqtProperty(QPointF, fset=_set_end)
class Example(QWidget):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
hbox = QHBoxLayout(self)
self.button = QPushButton("Start", self)
self.button.setSizePolicy(QSizePolicy.Fixed, QSizePolicy.Fixed)
hbox.addWidget(self.button)
hbox.addSpacing(40)
self.line = MyLine()
self.line.setLine(0, 0, 10, 10)
scene = QGraphicsScene()
scene.addItem(self.line)
view = QGraphicsView(scene)
hbox.addWidget(view)
self.anim = QPropertyAnimation(self.line, b"end") # crash without error here
# self.anim.setDuration(2500)
# self.anim.setLoopCount(1)
# self.anim.setStartValue(QPointF(10, 10))
# self.anim.setEndValue(QPointF(200, 200))
# self.button.clicked.connect(self.anim.start)
self.setGeometry(300, 300, 380, 250)
self.setWindowTitle('Color anim')
self.show()
if __name__ == "__main__":
app = QApplication([])
ex = Example()
ex.show()
app.exec_()
You have to use QGraphicsView, QGraphicsScene with QGraphicsLineItem as I show below:
from PyQt5 import QtCore, QtGui, QtWidgets
class LineAnimation(QtCore.QObject):
def __init__(self, parent=None):
super(LineAnimation, self).__init__(parent)
self.m_line = QtCore.QLineF()
self.m_item = QtWidgets.QGraphicsLineItem()
self.m_item.setLine(self.m_line)
self.m_item.setPen(
QtGui.QPen(
QtGui.QColor("salmon"),
10,
QtCore.Qt.SolidLine,
QtCore.Qt.SquareCap,
QtCore.Qt.RoundJoin,
)
)
self.m_animation = QtCore.QPropertyAnimation(
self,
b"p2",
parent=self,
startValue=QtCore.QPointF(0, 0),
endValue=QtCore.QPointF(200, 200),
duration=5 * 1000,
)
self.m_animation.start()
def p1(self):
return self.m_line.p1()
def setP1(self, p1):
self.m_line.setP1(p1)
self.m_item.setLine(self.m_line)
def p2(self):
return self.m_line.p2()
def setP2(self, p2):
self.m_line.setP2(p2)
self.m_item.setLine(self.m_line)
p1 = QtCore.pyqtProperty(QtCore.QPointF, fget=p1, fset=setP1)
p2 = QtCore.pyqtProperty(QtCore.QPointF, fget=p2, fset=setP2)
class MainWindow(QtWidgets.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
scene = QtWidgets.QGraphicsScene(self)
view = QtWidgets.QGraphicsView(
scene, alignment=QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop
)
self.setCentralWidget(view)
line_animation = LineAnimation(self)
scene.addItem(line_animation.m_item)
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
w = MainWindow()
w.resize(640, 480)
w.show()
sys.exit(app.exec_())
This question already has an answer here:
How to fix error in my pyqt programm (first argument of unbound method must have type 'QDialog') ?
(1 answer)
Closed 3 years ago.
I'm trying to build a GUI app using PyQt5 and Python 3.7 and I've decided to break the code in different modules. When i try to import a function that creates an instance of a custom widget, an error related to 'sis'. What I read is that 'sis' is a way of encapsulation C/C++ code to be run in python. But how can I work with that?
This is the code that runs the app:
import sys
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QApplication, QMainWindow
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setGeometry(10,35,1500,800)
self.setWindowTitle("Cotizador TuCheff")
#self.setWindowIcon(QtGui.QIcon(''))
mainWindow(self)
def mainWindow(self):
from PyQt5 import QtCore, QtGui, QtWidgets
from Pages.Quote import quote
barMenu = QtWidgets.QTabWidget(self)
tab1 = QtWidgets.QWidget()
quoteLayout = QtWidgets.QVBoxLayout()
quoteGenerator = quote.makeQuoteWindow()
quoteLayout.addWidget(quoteGenerator)
tab1.setLayout(quoteLayout)
barMenu.addTab(tab1, "&Nueva CotizaciĆ³n")
self.setCentralWidget(barMenu)
if __name__ == "__main__":
app = QApplication([])
window = MainWindow()
window.show()
app.exec_()
And file, where I try to get a custom widget, is:
from PyQt5 import QtCore, QtWidgets
from PyQt5.QtWidgets import QApplication
import sys
def makeQuoteWindow():
quoteWindow = QuoteWindow
quoteWindow.create()
#app = QApplication([])
#window = quoteWindow()
#window.show()
#status = app.exec_()
#sys.exit(status)
class QuoteWindow(QtWidgets.QWidget):
def __init__(self):
super(QuoteWindow, self).__init__()
def create(self):
mainWidget = QtWidgets.QWidget()
vLayout1 = QtWidgets.QVBoxLayout()
#=======------------------------ UPPER SIDE -------------------
hLayout1 = QtWidgets.QHBoxLayout()
##A LOT OF WIDGETS AND LAYOUTS
hLayout2 = QtWidgets.QHBoxLayout()
#display content
vLayout1.addLayout(hLayout1)
vLayout1.addLayout(hLayout2)
hLayout2.addItem(vSpacer1)
mainWidget.setLayout(vLayout1)
return mainWidget
if __name__ == "__main__":
makeQuoteWindow()
The error is:
TypeError: create(self, window: sip.voidptr = 0, initializeWindow: bool = True, destroyOldWindow: bool = True): first argument of unbound method must have type 'QWidget'
Try it:
main.py
import sys
from PyQt5 import QtCore, QtWidgets, QtGui
from PyQt5.QtWidgets import QApplication, QMainWindow
# from Pages.Quote import quote
from Quote import QuoteWindow
class MainWindow(QMainWindow):
def __init__(self):
super(MainWindow, self).__init__()
self.setGeometry(10,35,1500,800)
self.setWindowTitle("Cotizador TuCheff")
self.setWindowIcon(QtGui.QIcon('im.png'))
# mainWindow(self)
self.mainWindow()
def mainWindow(self):
# from Pages.Quote import quote
self.quoteWindow = QuoteWindow() # +++
barMenu = QtWidgets.QTabWidget(self)
tab1 = QtWidgets.QWidget()
quoteLayout = QtWidgets.QVBoxLayout()
# quoteGenerator = quote.makeQuoteWindow()
# quoteLayout.addWidget(quoteGenerator)
quoteLayout.addWidget(self.quoteWindow) # +++
tab1.setLayout(quoteLayout)
barMenu.addTab(tab1, "&Nueva CotizaciĆ³n")
self.setCentralWidget(barMenu)
if __name__ == "__main__":
app = QApplication([])
window = MainWindow()
window.show()
app.exec_()
Quote.py
from PyQt5 import QtCore, QtWidgets, QtGui
class QuoteWindow(QtWidgets.QWidget):
def __init__(self):
super(QuoteWindow, self).__init__()
def create(self):
mainWidget = QtWidgets.QWidget()
vLayout1 = QtWidgets.QVBoxLayout()
#=======------------------------ UPPER SIDE -------------------
hLayout1 = QtWidgets.QHBoxLayout()
##A LOT OF WIDGETS AND LAYOUTS
hLayout2 = QtWidgets.QHBoxLayout()
#display content
vLayout1.addLayout(hLayout1)
vLayout1.addLayout(hLayout2)
hLayout2.addItem(vSpacer1)
mainWidget.setLayout(vLayout1)
return mainWidget