I need to add pixmap to my rectangles. When I press the click button then my pixmap will be added to one by one in my rectangles but I got this attribute error. Can any one please guide me how to solve this error? I tried so many ways but I didn't get the proper output.
Thank you in advance.
Given below is my code:
from pyface.qt import QtGui, QtCore
import sys
global X,Y
class ScanView(QtGui.QGraphicsView):
def __init__(self,X=5, Y=5, parent=None):
super(ScanView, self).__init__(parent)
self.row = X
self.cols = Y
self.squareLB = 50
self.width = Y*self.squareLB+2*self.squareLB
self.height = X*self.squareLB+2*self.squareLB
self.List = []
if self.width>708:
self.scene = QtGui.QGraphicsScene(0,0,self.width,self.height)
for i in range(self.row):
for j in range(self.cols):
item = self.scene.addRect(QtCore.QRectF(0,0,self.squareLB,self.squareLB))
item.setPos(self.squareLB+j*self.squareLB, X*self.squareLB-(i*self.squareLB))
self.List.append(item)
else:
self.scene = QtGui.QGraphicsScene(0,0,708,self.height)
self.marginLR = (708.0-Y*self.squareLB)/2.0
for i in range(self.row):
for j in range(self.cols):
item = self.scene.addRect(QtCore.QRectF(0,0,self.squareLB,self.squareLB))
item.setPos(self.marginLR+j*self.squareLB, X*self.squareLB-(i*self.squareLB))
self.List.append(item)
self.setScene(self.scene)
class Settings(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Settings, self).__init__(parent)
spacer = QtGui.QWidget(self)
spacer.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
self.vbox = QtGui.QVBoxLayout()
self.save = QtGui.QPushButton("save")
self.open= QtGui.QPushButton("open")
self.folder= QtGui.QPushButton("Folder")
self.folder.clicked.connect(self.showSettings)
self.vbox.addWidget(self.save)
self.vbox.addWidget(self.open)
self.vbox.addWidget(self.folder)
self.grid = QtGui.QGridLayout()
self.grid.addLayout(self.vbox,0,0)
self.scrollArea = QtGui.QScrollArea()
self.scrollArea.setBackgroundRole(QtGui.QPalette.Light)
self.scrollArea.setWidgetResizable(True)
self.grid.addWidget(self.scrollArea,0,1)
self.setCentralWidget(QtGui.QWidget(self))
self.centralWidget().setLayout(self.grid)
self.setGeometry(200,100,300,300)
self.show()
def showSettings(self):
self.MyView = ScanView(5,5)
self.vbox2 = QtGui.QVBoxLayout()
self.Scanbtn1 = QtGui.QPushButton(("click"))
self.Scanbtn1.clicked.connect(self.on_clicked)
self.vbox2.addWidget(self.Scanbtn1)
self.newwidget = QtGui.QWidget()
self.glayout = QtGui.QGridLayout(self.newwidget)
self.glayout.addWidget(self.MyView,0,0)
self.Sw = QtGui.QWidget()
self.Sw.setLayout(self.vbox2)
# self.Sw.setFixedWidth(width - self.scrollArea.viewport().width())
self.glayout.addWidget(self.Sw,0,1)
self.scrollArea.setWidget(self.newwidget)
def on_clicked(self):
print "hellloooooo"
filename1 = "./img/tick.png"
pixmap = QtGui.QPixmap(filename1)
if not pixmap.isNull():
self.MyView.add_pixmap(pixmap)
# pic = QtGui.QPixmap("./img/tick.png")
# scene.addItem(QtGui.QGraphicsPixmapItem(pic))
# # view = self.gv
# self.MyView.setScene(scene)
# self.MyView.setRenderHint(QtGui.QPainter.Antialiasing)
# self.MyView.show()
def main():
app = QtGui.QApplication(sys.argv)
ex = Settings()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
You have that error because scene does not exist in the Settings class, self.scene is a member of the ScanView class plus self.scene is different from scene.
Going to the problem, you must add as a child of the rectangles and you must also change the size of the pixmap is necessary. To obtain the first rectangle you must store it in a list and then create an iterator.
import sys
from pyface.qt import QtGui, QtCore
class ScanView(QtGui.QGraphicsView):
def __init__(self,X=5, Y=5, parent=None):
super(ScanView, self).__init__(parent)
self._squares = []
n_rows, n_cols = X, Y
squareLB = 50
width, height = (Y + 2)*squareLB, (X + 2)*squareLB
self._scene = QtGui.QGraphicsScene(0, 0, max(708, width), height)
p = squareLB if width > 708 else (708.0-Y*squareLB)/2.0
for i in range(n_rows):
for j in range(n_cols):
it = self._scene.addRect(0, 0, squareLB, squareLB)
it.setPos(p + j*squareLB, i*squareLB)
self._squares.append(it)
self.setScene(self._scene)
class Settings(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Settings, self).__init__(parent)
self.save = QtGui.QPushButton("save")
self.open = QtGui.QPushButton("open")
self.folder = QtGui.QPushButton("Folder", clicked=self.showSettings)
central_widget = QtGui.QWidget()
self.setCentralWidget(central_widget)
vbox = QtGui.QVBoxLayout()
vbox.addWidget(self.save)
vbox.addWidget(self.open)
vbox.addWidget(self.folder)
self.scrollArea = QtGui.QScrollArea(widgetResizable=True)
self.scrollArea.setBackgroundRole(QtGui.QPalette.Light)
hlay = QtGui.QHBoxLayout(central_widget)
hlay.addLayout(vbox)
hlay.addWidget(self.scrollArea)
self.setGeometry(200, 100, 300, 300)
def showSettings(self):
self.view = ScanView(5, 5)
self.scanbtn = QtGui.QPushButton("click", clicked=self.on_clicked)
self.newwidget = QtGui.QWidget()
hlay = QtGui.QHBoxLayout(self.newwidget)
hlay.addWidget(self.view)
hlay.addWidget(self.scanbtn)
self.scrollArea.setWidget(self.newwidget)
self._iter_squares = iter(self.view._squares)
def on_clicked(self):
filename = "./img/tick.png"
pixmap = QtGui.QPixmap(filename)
if pixmap.isNull():
return
try:
it = next(self._iter_squares)
except StopIteration:
pass
else:
pixmap = pixmap.scaled(it.rect().size().toSize())
pixmap_it = QtGui.QGraphicsPixmapItem(pixmap, it)
def main():
app = QtGui.QApplication(sys.argv)
ex = Settings()
ex.show()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
Related
Start of the application
Plot the Graph
Full Screen
I have an application with 4 Box on the main window, and I want to had a full screen button in a windows which plot some graph, like on the Pictures on the top.
I first try a method to creating a fullScreen function in my code, linked to the button, but it is no work.
Here is my try :
class mainApplication(QWidget):
def __init__(self, parent=None):
super(mainApplication, self).__init__(parent)
self.layoutMap = {}
self.buttonMap = {}
# Figure Bottom Right
self.figure = plt.figure(figsize=(15,5))
self.figure.set_facecolor('0.915')
self.canvas = FigureCanvas(self.figure)
# Main Figure
self.setGeometry(600, 300, 1000, 600)
self.topLeft()
self.topRight()
self.bottomLeft()
self.bottomRight()
mainLayout = QGridLayout()
mainLayout.addWidget(self.topLeftBox, 1, 0)
mainLayout.addWidget(self.topRightBox, 1, 1)
mainLayout.addWidget(self.bottomLeftBox, 2, 0)
mainLayout.addWidget(self.bottomRightBox, 2, 1)
mainLayout.setRowStretch(1, 1)
mainLayout.setRowStretch(2, 1)
mainLayout.setColumnStretch(0, 1)
mainLayout.setColumnStretch(1, 1)
self.saveLayout(mainLayout, "main")
self.setLayout(mainLayout)
self.setWindowTitle("Title")
QApplication.setStyle("Fusion")
self.show()
def bottomRight(self):
self.bottomRightBox = QGroupBox("Bottom Right")
# Create Select Button
chooseButton = QPushButton("Select")
chooseButton.setMaximumWidth(100)
chooseButton.setMaximumHeight(20)
self.saveButton(chooseButton)
chooseButton.clicked.connect(self.selectFunction)
# Create Full Screen Button
fullScreenButton = QPushButton("Full")
fullScreenButton.setMaximumWidth(100)
fullScreenButton.setMaximumHeight(20)
self.saveButton(fullScreenButton)
fullScreenButton.clicked.connect(self.swichFullScreen)
# Create Layout
layout = QVBoxLayout()
layout.addWidget(self.canvas)
layout.addWidget(chooseButton)
layout.addWidget(fullScreenButton)
layout.addStretch(1)
self.saveLayout(layout, "full")
# Add Layout to GroupBox
self.bottomRightBox.setLayout(layout)
def selectFunction(self):
# Select Data
filePath, _ = QtWidgets.QFileDialog.getOpenFileName(self, 'Open file', '/Data/')
df = pd.read_csv(str(filePath))
x = df.x.tolist()
y = df.y.tolist()
# Create Figure
self.figure.clf()
ax = self.figure.add_subplot(111)
ax.plot(x, y)
ax.set_facecolor('0.915')
ax.set_title('Graphique')
# Draw Graph
self.canvas.draw()
def saveLayout(self,obj, text):
self.layoutMap[text] = obj
def findLayout(self,text):
return self.layoutMap[text]
def saveButton(self,obj):
self.buttonMap[obj.text()] = obj
def findButton(self,text):
return self.buttonMap[text]
def swichFullScreen(self):
self.setLayout(self.findLayout("full"))
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = mainApplication()
sys.exit(app.exec_())
Have you an idea? because for example, if in my initialization I don't do :
self.setLayout(mainLayout)
but :
swichFullScreen()
I have the result that I want, so why call this fonction after the creation of my main layout don't work?
Moreover, I have try an other thing adapter from this : PyQt: Change GUI Layout after button is clicked
But it still not worked because when I clic on the button "full", it switch very well, but the normalWindow object has been delete so the button select stop to work.
If you have a solution for my first idea, I prefer because it avoid the creation of other class, but if it is not possible and that you find a solution for the second solution to avoid the destruction of the object, I take it too.
Here the code for my second solution :
class fullScreenApplication(QWidget):
def __init__(self, parent=None):
super(fullScreenApplication, self).__init__(parent)
self.setGeometry(600, 300, 1000, 600)
class MainWindow(QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
self.setGeometry(600, 300, 1000, 600)
self.normalWindows()
def normalWindows(self):
self.normalBox = mainApplication(self)
self.setCentralWidget(self.normalBox)
self.normalBox.findButton("Full").clicked.connect(self.fullScreenWindow)
self.show()
def fullScreenWindow(self):
self.FullBox = fullScreenApplication(self)
self.FullBox.setLayout(self.normalBox.findLayout("full"))
self.normalBox.findButton("Full").clicked.connect(self.normalWindows)
self.normalBox.findButton("Select").clicked.connect(self.normalBox.selectFunction)
self.setCentralWidget(self.FullBox)
self.show()
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = MainWindow()
sys.exit(app.exec_())
Thank you
Try it:
import sys
import pandas as pd
import matplotlib.pyplot as plt
from PyQt5.QtCore import *
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
from matplotlib.figure import Figure
class mainApplication(QWidget):
def __init__(self, parent=None):
super(mainApplication, self).__init__(parent)
self.layoutMap = {}
self.buttonMap = {}
# Figure Bottom Right
self.figure = plt.figure(figsize=(15,5))
self.figure.set_facecolor('0.915')
self.canvas = FigureCanvas(self.figure)
# Main Figure
# self.setGeometry(600, 300, 1000, 600)
self.topLeftBox = self.topLeft()
self.topRightBox = self.topRight()
self.bottomLeftBox = self.bottomLeft()
self.bottomRight()
self.mainLayout = QGridLayout()
self.mainLayout.addWidget(self.topLeftBox, 1, 0)
self.mainLayout.addWidget(self.topRightBox, 1, 1)
self.mainLayout.addWidget(self.bottomLeftBox, 2, 0)
self.mainLayout.addWidget(self.bottomRightBox, 2, 1)
self.mainLayout.setRowStretch(1, 1)
self.mainLayout.setRowStretch(2, 1)
self.mainLayout.setColumnStretch(0, 1)
self.mainLayout.setColumnStretch(1, 1)
self.saveLayout(self.mainLayout, "main")
self.setLayout(self.mainLayout)
self.setWindowTitle("Title")
QApplication.setStyle("Fusion")
# self.show()
def bottomRight(self):
self.bottomRightBox = QGroupBox("Bottom Right")
# Create Select Button
chooseButton = QPushButton("Select")
chooseButton.setMaximumWidth(100)
chooseButton.setMaximumHeight(20)
self.saveButton(chooseButton)
chooseButton.clicked.connect(self.selectFunction)
# Create Full Screen Button
self.fullScreenButton = QPushButton("Full")
self.fullScreenButton.setMaximumWidth(100)
self.fullScreenButton.setMaximumHeight(20)
self.saveButton(self.fullScreenButton)
self.fullScreenButton.clicked.connect(self.swichFullScreen)
# Create Layout
layout = QVBoxLayout()
layout.addWidget(self.canvas)
layout.addWidget(chooseButton)
layout.addWidget(self.fullScreenButton)
layout.addStretch(1)
self.saveLayout(layout, "full")
# Add Layout to GroupBox
self.bottomRightBox.setLayout(layout)
def selectFunction(self):
# Select Data
filePath, _ = QFileDialog.getOpenFileName(self, 'Open file', '/Data/')
df = pd.read_csv(str(filePath))
x = df.x.tolist()
y = df.y.tolist()
# Create Figure
self.figure.clf()
ax = self.figure.add_subplot(111)
ax.plot(x, y)
ax.set_facecolor('0.915')
ax.set_title('Graphique')
# Draw Graph
self.canvas.draw()
def saveLayout(self,obj, text):
self.layoutMap[text] = obj
def findLayout(self,text):
return self.layoutMap[text]
def saveButton(self,obj):
self.buttonMap[obj.text()] = obj
def findButton(self,text):
return self.buttonMap[text]
def swichFullScreen(self):
# self.setLayout(self.findLayout("full")) # ---
# self.show() # ---
# +++ vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
if self.sender().text()== "Full":
self.topLeftBox.hide()
self.topRightBox.hide()
self.bottomLeftBox.hide()
self.bottomRightBox.hide()
self.mainLayout.addWidget(self.bottomRightBox, 0, 0, 1, 2)
self.bottomRightBox.show()
self.fullScreenButton.setText("NoFull")
else:
self.bottomRightBox.hide()
self.topLeftBox.show()
self.topRightBox.show()
self.bottomLeftBox.show()
self.mainLayout.addWidget(self.bottomRightBox, 2, 1)
self.bottomRightBox.show()
self.fullScreenButton.setText("Full")
def topLeft(self):
textEdit = QTextEdit()
return textEdit
def topRight(self):
textEdit = QTextEdit()
return textEdit
def bottomLeft(self):
textEdit = QTextEdit()
return textEdit
# +++ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if __name__ == '__main__':
app = QApplication(sys.argv)
mainWindow = mainApplication()
mainWindow.setGeometry(200, 100, 1000, 600)
mainWindow.show()
sys.exit(app.exec_())
I am trying to build a layout using PySide and I have run into a situation where I would like to keep a widget group in a separate class and call it dynamically.
I looked at few examples from this site which sort of gives me an idea but still I am not able to resolve this issue on my own. Here is the sample code of the layout I am building and it will be very helpful if someone can help me solve this issue.
-Thanks in advance
import PySide2.QtCore as QtCore
import PySide2.QtGui as QtGui
import PySide2.QtWidgets as QtGuiWidgets
class TabDialog(QtGuiWidgets.QDialog):
def __init__(self, parent=None):
super(TabDialog, self).__init__(parent)
argument = "Temp"
calldisplay = display_elements()
tabWidget = QtGuiWidgets.QTabWidget()
tabWidget.addTab(tab1(argument), "tab1")
tabWidget.addTab(tab2(argument), "tab2")
buttonBox = QtGuiWidgets.QDialogButtonBox(
QtGuiWidgets.QDialogButtonBox.Ok | QtGuiWidgets.QDialogButtonBox.Cancel)
buttonBox.accepted.connect(self.accept)
buttonBox.rejected.connect(self.reject)
mainLayout = QtGuiWidgets.QVBoxLayout()
mainLayout.addWidget(tabWidget)
mainLayout.addWidget(buttonBox)
self.setLayout(mainLayout)
self.setWindowTitle("Load All Elements")
self.show()
class tab1(QtGuiWidgets.QWidget):
def __init__(self, calldisplay, parent=None):
super(tab1, self).__init__(parent)
self.layerfilterGroup = QtGuiWidgets.QLabel("Filter 1")
self.peopleGroup = QtGuiWidgets.QGroupBox("Filter 2")
self.dateGroup = QtGuiWidgets.QGroupBox("Filter 3")
self.loadGroup = QtGuiWidgets.QLabel("Load elements")
self.filterGroup = QtGuiWidgets.QGroupBox("Filters")
self.filterGroup.setGeometry(100, 100, 700, 550)
self.filterLayout = QtGuiWidgets.QVBoxLayout()
for key in range(15):
self.btn = QtGuiWidgets.QCheckBox(str(key))
self.btn.setChecked(True)
self.filterLayout.addWidget(self.btn)
self.filterGroup.setLayout(self.filterLayout)
self.filterscroll = QtGuiWidgets.QScrollArea()
self.fslayout = QtGuiWidgets.QVBoxLayout()
self.filterscroll.setWidget(self.filterGroup)
self.fslayout.addWidget(self.filterscroll)
self.artist = ["All", "N/A", "N/A", "N/A"]
self.acombos = QtGuiWidgets.QComboBox()
self.acombos.addItems(self.artist)
self.all_label = QtGuiWidgets.QLabel()
self.all_label.setText('All')
self.all_label.setGeometry(160, 40, 80, 30)
self.late_label = QtGuiWidgets.QLabel()
self.late_label.setText('Latest')
self.late_label.setGeometry(160, 40, 80, 30)
self.dslider = QtGuiWidgets.QSlider(QtCore.Qt.Horizontal, self)
self.artistlayout = QtGuiWidgets.QVBoxLayout()
self.artistlayout.addWidget(self.acombos)
self.peopleGroup.setLayout(self.artistlayout)
self.datelayout = QtGuiWidgets.QHBoxLayout()
self.datelayout.addWidget(self.all_label)
self.datelayout.addWidget(self.dslider)
self.datelayout.addWidget(self.late_label)
self.dateGroup.setLayout(self.datelayout)
self.rgroup = QtGuiWidgets.QGroupBox("Elements")
self.rgroup.setGeometry(100, 100, 700, 750)
self.rlayout = QtGuiWidgets.QVBoxLayout()
########## This is Working###############
for key in range(15):
self.btn = QtGuiWidgets.QCheckBox(str(key))
self.btn.setChecked(True)
self.rlayout.addWidget(self.btn)
self.rgroup.setLayout(self.rlayout)
############ want to do it this way############
#self.rlayout.addWidget(calldisplay)
#self.rgroup.setLayout(self.rlayout)
self.rscroll = QtGuiWidgets.QScrollArea()
self.rlayout = QtGuiWidgets.QVBoxLayout()
self.rscroll.setWidget(self.rgroup)
self.rlayout.addWidget(self.rscroll)
self.mainLayout = QtGuiWidgets.QVBoxLayout()
self.mainLayout.addWidget(self.layerfilterGroup)
self.mainLayout.addWidget(self.filterscroll)
self.mainLayout.addWidget(self.peopleGroup)
self.mainLayout.addWidget(self.dateGroup)
self.mainLayout.addWidget(self.loadGroup)
self.mainLayout.addWidget(self.rscroll)
self.setLayout(self.mainLayout)
##### call this class dynamically######
class display_elements(QtGuiWidgets.QWidget):
def __init__(self, parent=None):
super(display_elements, self).__init__(parent)
self.rgroup = QtGuiWidgets.QGroupBox("Available Elements")
self.rgroup.setGeometry(400, 400, 700, 750)
self.rlayout = QtGuiWidgets.QVBoxLayout()
for key in range(15):
self.btn = QtGuiWidgets.QCheckBox(str(key))
self.btn.setChecked(True)
self.rlayout.addWidget(self.btn)
self.rgroup.setLayout(self.rlayout)
class tab2(QtGuiWidgets.QWidget):
def __init__(self, fileInfo, parent=None):
super(tab2, self).__init__(parent)
ex = TabDialog()
One of the errors I see is that you point as the first argument of tab1 to calldisplay that I guess is the widget you want to set but you are passing it as an argument to "argument" which is a string, so a first change is to change it .
On the other hand if you are going to use layouts forget about setGeometry() since now the geometry is handled by the QLayouts.
And finally, your display_elements class is not implemented correctly since the rgroup is not added to the widget and for this you must use a layout.
Considering the above, the solution is the following:
import PySide2.QtCore as QtCore
import PySide2.QtGui as QtGui
import PySide2.QtWidgets as QtGuiWidgets
class TabDialog(QtGuiWidgets.QDialog):
def __init__(self, parent=None):
super(TabDialog, self).__init__(parent)
argument = "Temp"
calldisplay = display_elements()
tabWidget = QtGuiWidgets.QTabWidget()
tabWidget.addTab(tab1(calldisplay), "tab1")
tabWidget.addTab(tab2(argument), "tab2")
buttonBox = QtGuiWidgets.QDialogButtonBox(
QtGuiWidgets.QDialogButtonBox.Ok | QtGuiWidgets.QDialogButtonBox.Cancel)
buttonBox.accepted.connect(self.accept)
buttonBox.rejected.connect(self.reject)
mainLayout = QtGuiWidgets.QVBoxLayout()
mainLayout.addWidget(tabWidget)
mainLayout.addWidget(buttonBox)
self.setLayout(mainLayout)
self.setWindowTitle("Load All Elements")
self.show()
class tab1(QtGuiWidgets.QWidget):
def __init__(self, calldisplay, parent=None):
super(tab1, self).__init__(parent)
self.layerfilterGroup = QtGuiWidgets.QLabel("Filter 1")
self.peopleGroup = QtGuiWidgets.QGroupBox("Filter 2")
self.dateGroup = QtGuiWidgets.QGroupBox("Filter 3")
self.loadGroup = QtGuiWidgets.QLabel("Load elements")
self.filterGroup = QtGuiWidgets.QGroupBox("Filters")
self.filterGroup.setGeometry(100, 100, 700, 550)
self.filterLayout = QtGuiWidgets.QVBoxLayout()
for key in range(15):
self.btn = QtGuiWidgets.QCheckBox(str(key))
self.btn.setChecked(True)
self.filterLayout.addWidget(self.btn)
self.filterGroup.setLayout(self.filterLayout)
self.filterscroll = QtGuiWidgets.QScrollArea()
self.fslayout = QtGuiWidgets.QVBoxLayout()
self.filterscroll.setWidget(self.filterGroup)
self.fslayout.addWidget(self.filterscroll)
self.artist = ["All", "N/A", "N/A", "N/A"]
self.acombos = QtGuiWidgets.QComboBox()
self.acombos.addItems(self.artist)
self.all_label = QtGuiWidgets.QLabel()
self.all_label.setText('All')
self.all_label.setGeometry(160, 40, 80, 30)
self.late_label = QtGuiWidgets.QLabel()
self.late_label.setText('Latest')
self.late_label.setGeometry(160, 40, 80, 30)
self.dslider = QtGuiWidgets.QSlider(QtCore.Qt.Horizontal, self)
self.artistlayout = QtGuiWidgets.QVBoxLayout()
self.artistlayout.addWidget(self.acombos)
self.peopleGroup.setLayout(self.artistlayout)
self.datelayout = QtGuiWidgets.QHBoxLayout()
self.datelayout.addWidget(self.all_label)
self.datelayout.addWidget(self.dslider)
self.datelayout.addWidget(self.late_label)
self.dateGroup.setLayout(self.datelayout)
self.rgroup = QtGuiWidgets.QGroupBox("Elements")
self.rlayout = QtGuiWidgets.QVBoxLayout()
self.rlayout.addWidget(calldisplay)
self.rgroup.setLayout(self.rlayout)
self.rscroll = QtGuiWidgets.QScrollArea()
self.rlayout = QtGuiWidgets.QVBoxLayout()
self.rscroll.setWidget(self.rgroup)
self.rlayout.addWidget(self.rscroll)
self.mainLayout = QtGuiWidgets.QVBoxLayout()
self.mainLayout.addWidget(self.layerfilterGroup)
self.mainLayout.addWidget(self.filterscroll)
self.mainLayout.addWidget(self.peopleGroup)
self.mainLayout.addWidget(self.dateGroup)
self.mainLayout.addWidget(self.loadGroup)
self.mainLayout.addWidget(self.rscroll)
self.setLayout(self.mainLayout)
class display_elements(QtGuiWidgets.QWidget):
def __init__(self, parent=None):
super(display_elements, self).__init__(parent)
self.rgroup = QtGuiWidgets.QGroupBox("Available Elements")
lay = QtGuiWidgets.QVBoxLayout()
for key in range(15):
btn = QtGuiWidgets.QCheckBox(str(key))
btn.setChecked(True)
lay.addWidget(btn)
rlayout = QtGuiWidgets.QVBoxLayout(self)
rlayout.setContentsMargins(0, 0, 0, 0)
rlayout.addWidget(self.rgroup)
self.rgroup.setLayout(lay)
class tab2(QtGuiWidgets.QWidget):
def __init__(self, fileInfo, parent=None):
super(tab2, self).__init__(parent)
if __name__ == '__main__':
import sys
app = QtGuiWidgets.QApplication(sys.argv)
ex = TabDialog()
ex.show()
sys.exit(app.exec_())
Here is my sample code,i want to print the my coordinates of x,y positions by using the mouse press event,i got this error can any one please help me and i want to display the my graphics view in middle of the scrollArea.
Given bellow is my code:
from pyface.qt import QtGui, QtCore
import sys
class MyView(QtGui.QGraphicsView):
def __init__(self):
QtGui.QGraphicsView.__init__(self)
self.row = 2
self.cols = 4
self.scene = QtGui.QGraphicsScene(0,0,500,500)
self.List = []
for i in range(self.row):
for j in range(self.cols):
item = self.scene.addRect(QtCore.QRectF(0,0,30,30))
item.setPos(30+j*30,500-i*30-60)
print item.scenePos()
self.List.append(item)
self.setScene(self.scene)
def mousePressEvent(self,event):
super(MyView,self).mousePressEvent(event)
p = QtCore.QPointF(event.pos())
print "positonnnnnnnnnnnnnnnn", p
item = self.scene.itemAt(p)
print "#########################2"
print item.scenePos()
class Settings(QtGui.QMainWindow):
def __init__(self, parent=None):
super(Settings, self).__init__(parent)
spacer = QtGui.QWidget(self)
spacer.setSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Expanding)
QtGui.QToolTip.setFont(QtGui.QFont('SansSerif', 10))
self.vbox = QtGui.QVBoxLayout()
self.save = QtGui.QPushButton("save")
self.open= QtGui.QPushButton("open")
self.folder= QtGui.QPushButton("Folder")
self.folder.clicked.connect(self.showSettings)
self.vbox.addWidget(self.save)
self.vbox.addWidget(self.open)
self.vbox.addWidget(self.folder)
self.grid = QtGui.QGridLayout()
self.grid.addLayout(self.vbox,0,0)
self.scrollArea = QtGui.QScrollArea()
self.scrollArea.setBackgroundRole(QtGui.QPalette.Light)
self.scrollArea.setWidgetResizable(True)
self.grid.addWidget(self.scrollArea,0,1)
self.setCentralWidget(QtGui.QWidget(self))
self.centralWidget().setLayout(self.grid)
self.setGeometry(200,100,300,300)
self.show()
def showSettings(self):
self.newwidget = QtGui.QWidget()
self.glayout = QtGui.QGridLayout(self.newwidget)
self.MyView = MyView()
self.glayout.addWidget(self.MyView,0,1)
self.scrollArea.setWidget(self.newwidget)
def main():
app = QtGui.QApplication(sys.argv)
ex = Settings()
sys.exit(app.exec_())
if __name__ == '__main__':
main()
The coordinates of the items are different to the coordinates of the window, in the case of event.pos() returns the position of the mouse with respect to the viewport of the QGraphicsView so you will have to convert it to coordinates of the scene with mapToScene(), by other side when using itemAt() could return None since in certain areas of the scene there are no items so it is advisable to verify
def mousePressEvent(self, event):
super(MyView,self).mousePressEvent(event)
p = self.mapToScene(event.pos())
item = self.scene.itemAt(p)
if item is not None:
print(item.scenePos())
To understand the different coordinate systems that handle the QGraphicsView, QGraphicsScene and the QGraphicsItems, I recommend reading Graphics View Framework.
Now I want that when a user clicks in a cell of the grid, it becomes editable and he can edit the cell values/images and update the data accordingly.
I don't wish to use the in-built edit, delete and update buttons of grid. How can I do that?please guide me.Thank you in advance
given bellow is my code:
import sys
from PyQt4 import QtCore, QtGui
class Setting:
WIDTH = 80
HEIGHT = 80
X, Y = 7, 5
class QS(QtGui.QGraphicsScene):
def __init__(self, parent=None):
super(QS, self).__init__(QtCore.QRectF(0, 0, X * Setting.WIDTH, Y * Setting.HEIGHT), parent)
def drawBackground(self, painter, rect):
width = X * Setting.WIDTH
height = Y * Setting.HEIGHT
l = QtCore.QLineF(QtCore.QPointF(0, 0), QtCore.QPointF(width, 0))
for _ in range(Y+1):
painter.drawLine(l)
l.translate(0, Setting.HEIGHT)
l = QtCore.QLineF(QtCore.QPointF(0, 0), QtCore.QPointF(0, height))
for _ in range(X+1):
painter.drawLine(l)
l.translate(Setting.WIDTH, 0)
pixmap = QtGui.QPixmap("checkmark.png").scaled(Setting.WIDTH,
Setting.HEIGHT,
QtCore.Qt.IgnoreAspectRatio,
QtCore.Qt.SmoothTransformation)
p = QtCore.QPointF()
for i in range(X):
p = QtCore.QPointF(Setting.WIDTH*i, 0)
for j in range(Y):
painter.drawPixmap(p, pixmap)
p += QtCore.QPointF(0, Setting.HEIGHT)
def mousePressEvent(self,evnt):
# print event
# print(dir(evnt))
print evnt.screenPos().x()
print evnt.screenPos().y()
self.ix = int(evnt.screenPos().x()/Setting.WIDTH)
self.ix = int(evnt.screenPos().y()/Setting.HEIGHT)
print self.ix,self.iy
class QV(QtGui.QGraphicsView):
pass
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
scene = QS(self)
view = QV(scene)
self.setCentralWidget(view)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
The most common way to establish options is to use a context menu, in it you create a menu where you add the QActions, and depending on the selection of the corresponding QAction will return, depending on the choice you must change the image or delete it as shown below (Take in when to draw the figures I used items):
import sys
from PyQt4 import QtCore, QtGui
class Setting:
WIDTH = 80
HEIGHT = 80
X, Y = 7, 5
class QS(QtGui.QGraphicsScene):
def __init__(self, parent=None):
super(QS, self).__init__(QtCore.QRectF(0, 0, X * Setting.WIDTH, Y * Setting.HEIGHT), parent)
pixmap = QtGui.QPixmap("checkmark.png").scaled(Setting.WIDTH, Setting.HEIGHT,
QtCore.Qt.IgnoreAspectRatio,
QtCore.Qt.SmoothTransformation)
for i in range(X):
p = QtCore.QPointF(Setting.WIDTH*i, 0)
for j in range(Y):
item = self.addPixmap(pixmap)
item.setPos(p)
p += QtCore.QPointF(0, Setting.HEIGHT)
def drawBackground(self, painter, rect):
width = X * Setting.WIDTH
height = Y * Setting.HEIGHT
l = QtCore.QLineF(QtCore.QPointF(0, 0), QtCore.QPointF(width, 0))
for _ in range(Y+1):
painter.drawLine(l)
l.translate(0, Setting.HEIGHT)
l = QtCore.QLineF(QtCore.QPointF(0, 0), QtCore.QPointF(0, height))
for _ in range(X+1):
painter.drawLine(l)
l.translate(Setting.WIDTH, 0)
class QV(QtGui.QGraphicsView):
def __init__(self, parent=None):
super(QV, self).__init__(parent)
self.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
self.customContextMenuRequested.connect(self.on_customContextMenuRequested)
def on_customContextMenuRequested(self, pos):
items = self.items(pos)
if items:
menu = QtGui.QMenu()
change_action = menu.addAction("Change image")
delete_action = menu.addAction("Delete")
action = menu.exec(self.mapToGlobal(pos))
if action is change_action:
filename = QtGui.QFileDialog.getOpenFileName(self,
"Open Image", QtCore.QDir.currentPath() , "Image Files (*.png *.jpg *.bmp)")
if filename:
pixmap = QtGui.QPixmap(filename)
if not pixmap.isNull():
pixmap = pixmap.scaled(Setting.WIDTH, Setting.HEIGHT,
QtCore.Qt.IgnoreAspectRatio, QtCore.Qt.SmoothTransformation)
for item in items:
if isinstance(item, QtGui.QGraphicsPixmapItem):
item.setPixmap(pixmap)
elif action is delete_action:
for it in reversed(items):
self.scene().removeItem(it)
del it
class MainWindow(QtGui.QMainWindow):
def __init__(self, parent=None):
super(MainWindow, self).__init__(parent)
scene = QS(self)
view = QV(scene)
self.setCentralWidget(view)
if __name__ == "__main__":
app = QtGui.QApplication(sys.argv)
w = MainWindow()
w.show()
sys.exit(app.exec_())
I m trying to resize a table widget inside a QVBoxlayout which I further add as a row to a QFormlayout in pyqt
I m currently adding a QVboxlayout which contains a table widget inside it as a row in a Qformlayout.
And the main aim is to strecth the Table widget till the end of the application window that it acquires the left over space on the window
Using the below code -
class PGSearchDetails():
def __init__(self,parent=None):
self.widget_pgsd = QWidget()
self.layout_pgsd = QFormLayout()
self.layout_pgsd.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy(2|1))
self.PG_Id = QLineEdit()
#rx = QRegExp("^\\D+[!,#,#,$,%,\^,&,*,(,),:,\",{,},?,<,>,|,+,-,~,]")
#rx = QRegExp(" (?!(#,#,$|%|\^|&|*|(|)|:|\"|{|}|?|<|>|\||+|-|~|!))[\\w]+")
str_rx = QRegExp("^[A-Za-z*]{20}(?!##$%^&*():\"\{\}?<>\|+-~!_-)")
adhr_rx = QRegExp("[A-Z0-9]{12}(?!##$%^&*():\"\{\}?<>\|+-~!_)")
val = QRegExpValidator(str_rx)
val3 = QRegExpValidator(adhr_rx)
self.PG_Id.setValidator(val3)
self.LastName = QLineEdit()
self.LastName.setValidator(val)
self.MobNum = QLineEdit()
qint_val = QIntValidator()
qint_val.setTop(10)
self.MobNum.setValidator(qint_val)
self.layout_pgsd.addRow("First Name",self.PG_Id)
self.layout_pgsd.addRow("Last Name",self.LastName)
self.layout_pgsd.addRow("Mobile Number",self.MobNum)
update_layout_pgsd = QHBoxLayout()
layout_test,table = dbv.Search_View(self.getT)
#layout_test.setGeometry(QRect(200,200,50,50))
#table.setMaximumHeight(800)
#table.setGeometry(200,200,200,200)
#table.setGeometry(1,1,1000,600)
table.resize(1000,600)
update_btn_pgsd = QPushButton('Update')
reset_btn_pgsd = QPushButton('Reset')
update_layout_pgsd.addWidget(update_btn_pgsd)
update_layout_pgsd.addWidget(reset_btn_pgsd)
self.layout_pgsd.addRow(update_layout_pgsd)
##Adding the Table Widget to FormLayot
self.layout_pgsd.addRow(layout_test)
update_btn_pgsd.clicked.connect(partial(self.database,table,self.MobNum,
self.LastName))
#self.widget.setLayout(self.layout_pgsd)
def returnLayout(self):
return self.layout_pgsd
def returnWidget(self):
return self.widget_pgsd
def getT(self,linedit):
print("LE--->",linedit.text())
QtableWidget setup ---
def Search_View(self):
print("Inside Search_view")
central_widget = QWidget() # Create a central widget
db_layout = QVBoxLayout()
#col_count = len(self.pg_details.__dict__.keys())
col_count = 3
table = QTableWidget() # Create a table
#central_widget.setGeometry(200,200,150,150)
#table.maximumSize()
#db_layout.setMaximumSize(200)
db_layout.setGeometry(QRect(0,0,100,30))
db_layout.addWidget(table)
##Tried resizing the Table widget but nothing seems to works
table.resize(1000,600)
table.setGeometry(0,2,1000,600)
#central_widget.resize(central_widget.sizeHint())
#central_widget.setColumnWidth(1000,600)
#db_layout.addItem(update_layout)
central_widget.setLayout(db_layout)
print("Geometry H--->",table.geometry().height())
print("Geometry W--->",table.geometry().width())
print("Geometry X--->",table.geometry().x())
print("Geometry Y--->",table.geometry().y())
return central_widget,table
After the resize function, The table geometry changes to 1000,600 but on the screen it is not reflected. On the app screen it remains the same size everytime
Also find the entire code which contains the Tablayouts as well and Stacked widget for individual radio buttons
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.tab_widget = MainTabWindow()
self.setCentralWidget(self.tab_widget)
self.show()
class MainTabWindow(QTabWidget):
def __init__(self,parent=None):
super(MainTabWindow, self).__init__(parent)
self.init_ui()
def init_ui(self):
self.setWindowTitle('PyQt5 Tab Example')
self.tab1 = QWidget()
self.addTab(self.tab1,"Search")
self.PGSearchTab()
def PGSearchTab(self):
print("Search Tab First Tab")
self.central_layout = QVBoxLayout()
self.stack1 = QWidget()
self.stack2 = QWidget()
self.stack3 = QWidget()
self.stack_widget = QStackedWidget()
button_layout = QHBoxLayout()
radio_button_1 = QRadioButton("Search")
radio_button_2 = QRadioButton("Add")
radio_button_3 = QRadioButton("Update")
button_layout.addWidget(radio_button_1)
button_layout.addWidget(radio_button_2)
button_layout.addWidget(radio_button_3)
self.central_layout.addItem(button_layout)
self.stack_widget.addWidget(self.stack1)
self.stack_widget.addWidget(self.stack2)
self.stack_widget.addWidget(self.stack3)
self.central_layout.addWidget(self.stack_widget)
radio_button_1.toggled.connect(lambda :self.SelectButtonCheck(radio_button_1))
self.setTabText(0,"Search")
update_layout = QHBoxLayout()
update_layout.setAlignment(QtCore.Qt.AlignBottom)
update_btn = QPushButton('Update')
reset_btn = QPushButton('Reset')
update_layout.addWidget(update_btn)
update_layout.addWidget(reset_btn)
self.tab1.setLayout(self.central_layout)
def SelectButtonCheck(self,b):
if b.text() == "Search":
if b.isChecked():
print(b.text()+ "is selected")
self.obj_pgsd = pgsd.PGSearchDetails()
layout = self.obj_pgsd.returnLayout()
if self.stack1.layout() is None:
self.stack1.setLayout(layout)
self.stack_widget.setCurrentIndex(0)
def main():
application = QApplication(sys.argv)
main_window = MainTabWindow()
main_window.show()
sys.exit(application.exec_())
if __name__ == '__main__':
main()
I do not seem to understand what is I m missing here
Any pointers would be appreciated.
Also find the working code to execute the above layout setup.
#!/usr/local/bin/python3
import sys
from PyQt5.QtWidgets import (QApplication, QWidget,QMainWindow,QLineEdit,QAction,
QLabel,QPushButton,QVBoxLayout,
QTabWidget,QFormLayout,QHBoxLayout,
QRadioButton,QCheckBox,QTextEdit,
QListView,QDialogButtonBox,QSizePolicy,QCalendarWidget)
from PyQt5 import QtCore
import PyQt5.Qt
from PyQt5.Qt import *
from PyQt5.QtCore import pyqtSlot
from PyQt5 import QtSql
from functools import partial
class MainWindow(QMainWindow):
def __init__(self):
super().__init__()
self.init_ui()
def init_ui(self):
self.tab_widget = MainTabWindow()
self.setCentralWidget(self.tab_widget)
self.show()
class MainTabWindow(QTabWidget):
def __init__(self,parent=None):
super(MainTabWindow, self).__init__(parent)
self.init_ui()
def init_ui(self):
self.setWindowTitle('PyQt5 Tab Example')
self.tab1 = QWidget()
self.addTab(self.tab1,"Search")
self.PGSearchTab()
def PGSearchTab(self):
print("Search Tab First Tab")
self.central_layout = QVBoxLayout()
self.stack1 = QWidget()
self.stack2 = QWidget()
self.stack3 = QWidget()
self.stack_widget = QStackedWidget()
button_layout = QHBoxLayout()
radio_button_1 = QRadioButton("Search")
radio_button_2 = QRadioButton("Add")
radio_button_3 = QRadioButton("Update")
button_layout.addWidget(radio_button_1)
button_layout.addWidget(radio_button_2)
button_layout.addWidget(radio_button_3)
self.central_layout.addItem(button_layout)
self.stack_widget.addWidget(self.stack1)
self.stack_widget.addWidget(self.stack2)
self.stack_widget.addWidget(self.stack3)
self.central_layout.addWidget(self.stack_widget)
radio_button_1.toggled.connect(lambda :self.SelectButtonCheck(radio_button_1))
self.setTabText(0,"Search")
update_layout = QHBoxLayout()
update_layout.setAlignment(QtCore.Qt.AlignBottom)
update_btn = QPushButton('Update')
reset_btn = QPushButton('Reset')
update_layout.addWidget(update_btn)
update_layout.addWidget(reset_btn)
self.tab1.setLayout(self.central_layout)
def SelectButtonCheck(self,b):
if b.text() == "Search":
if b.isChecked():
print(b.text()+ "is selected")
self.obj_pgsd = PGSearchDetails()
layout = self.obj_pgsd.returnLayout()
if self.stack1.layout() is None:
self.stack1.setLayout(layout)
self.stack_widget.setCurrentIndex(0)
class PGSearchDetails():
def __init__(self,parent=None):
self.widget_pgsd = QWidget()
self.layout_pgsd = QFormLayout()
self.layout_pgsd.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy(2|1))
self.PG_Id = QLineEdit()
#rx = QRegExp("^\\D+[!,#,#,$,%,\^,&,*,(,),:,\",{,},?,<,>,|,+,-,~,]")
#rx = QRegExp(" (?!(#,#,$|%|\^|&|*|(|)|:|\"|{|}|?|<|>|\||+|-|~|!))[\\w]+")
str_rx = QRegExp("^[A-Za-z*]{20}(?!##$%^&*():\"\{\}?<>\|+-~!_-)")
adhr_rx = QRegExp("[A-Z0-9]{12}(?!##$%^&*():\"\{\}?<>\|+-~!_)")
val = QRegExpValidator(str_rx)
val3 = QRegExpValidator(adhr_rx)
self.PG_Id.setValidator(val3)
self.LastName = QLineEdit()
self.LastName.setValidator(val)
self.MobNum = QLineEdit()
qint_val = QIntValidator()
qint_val.setTop(10)
self.MobNum.setValidator(qint_val)
self.layout_pgsd.addRow("First Name",self.PG_Id)
self.layout_pgsd.addRow("Last Name",self.LastName)
self.layout_pgsd.addRow("Mobile Number",self.MobNum)
update_layout_pgsd = QHBoxLayout()
layout_test,table = self.Search_View(self.getT)
#layout_test.setGeometry(QRect(200,200,50,50))
#table.setMaximumHeight(800)
#table.setGeometry(200,200,200,200)
#table.setGeometry(1,1,1000,600)
table.resize(1000,600)
update_btn_pgsd = QPushButton('Update')
reset_btn_pgsd = QPushButton('Reset')
update_layout_pgsd.addWidget(update_btn_pgsd)
update_layout_pgsd.addWidget(reset_btn_pgsd)
self.layout_pgsd.addRow(update_layout_pgsd)
##Adding the Table Widget to FormLayot
self.layout_pgsd.addRow(layout_test)
update_btn_pgsd.clicked.connect(partial(self.database,table,self.MobNum,
self.LastName))
#self.widget.setLayout(self.layout_pgsd)
def returnLayout(self):
return self.layout_pgsd
def returnWidget(self):
return self.widget_pgsd
def getT(self,linedit):
print("LE--->",linedit.text())
def Search_View(self,text):
print("Inside Search_view")
central_widget = QWidget() # Create a central widget
db_layout = QVBoxLayout()
#col_count = len(self.pg_details.__dict__.keys())
col_count = 3
table = QTableWidget() # Create a table
#central_widget.setGeometry(200,200,150,150)
#table.maximumSize()
#db_layout.setMaximumSize(200)
db_layout.setGeometry(QRect(0,0,100,30))
db_layout.addWidget(table)
##Tried resizing the Table widget but nothing seems to works
table.resize(1000,600)
table.setGeometry(0,2,1000,600)
#central_widget.resize(central_widget.sizeHint())
#central_widget.setColumnWidth(1000,600)
#db_layout.addItem(update_layout)
central_widget.setLayout(db_layout)
print("Geometry H--->",table.geometry().height())
print("Geometry W--->",table.geometry().width())
print("Geometry X--->",table.geometry().x())
print("Geometry Y--->",table.geometry().y())
return central_widget,table
def SqlExec(self,text):
db = QtSql.QSqlDatabase.addDatabase('QMYSQL')
db.setHostName('localhost')
db.setDatabaseName('Test')
db.setUserName('root')
db.open()
query = QtSql.QSqlQuery()
select = "select * from Test.PG_Details where PG_Id=?"# where PG_Id = 1"
query.prepare(select)
indexes = range(3)
print("TEXT----->",text)
query.addBindValue(text)
#query.exec_(select)
query.exec_()
print("Sizze----",query.size())
row_count = query.size()
db.record('PG_Details')
col_list = []
for i in range(db.record('PG_Details').count()):
print("FIELD----->",db.record('PG_Details').field(i).name())
col_list.append(db.record('PG_Details').field(i).name())
db.close()
return query,row_count,col_list
def database(self,table,text,text2):
text = text.text()
query_result,row_count,col_list = self.SqlExec(text)
i = 0
table.setColumnCount(3) #Set three columns
table.setRowCount(row_count)
table.setHorizontalHeaderLabels(col_list)
while query_result.next():
#print(query_result.value(i))
result_row = [query_result.value(index) for index in range(query_result.record().count())]
#print("RR--->",result_row)
for idx,val in enumerate(result_row):
#print("IDX----->",idx)
table.setItem(i, idx, QTableWidgetItem(val))
i = i + 1
def main():
application = QApplication(sys.argv)
main_window = MainTabWindow()
main_window.show()
sys.exit(application.exec_())
if __name__ == '__main__':
main()
The problem is that QFormLayout makes every time you add a widget using addRow () uses strech, the solution is to use a QVBoxLayout, and in that QVBoxLayout is to pass the QFormLayout and the layout_test.
class PGSearchDetails():
def __init__(self,parent=None):
self.widget_pgsd = QWidget()
self.layout = QVBoxLayout() # <---
self.layout_pgsd = QFormLayout()
self.layout.addLayout(self.layout_pgsd) # <---
self.layout_pgsd.setFieldGrowthPolicy(QFormLayout.FieldGrowthPolicy(2|1))
...
self.layout_pgsd.addRow(update_layout_pgsd)
##Adding the Table Widget to FormLayot
# self.layout_pgsd.addRow(layout_test)
self.layout.addWidget(layout_test) # <---
update_btn_pgsd.clicked.connect(partial(self.database,table,self.MobNum,
self.LastName))
def returnLayout(self):
return self.layout # <---