Reputation: 1
I have created two custom widgets using pyqt5. I want to show both of them in my mainwindow.But the problem is that only any one of them is showing up.Only the object which is being created at second number is visible.
class Mainwindow(QtWidgets.QMainWindow):
xfactor = 0.0
yfactor = 0.0
windetails = []
def __init__(self):
QtWidgets.QMainWindow.__init__(self)
# Ui_MainWindow.__init__(self)
# self.setupUi(self)
self.setresolutionparams()
self.setupobject()
def setresolutionparams(self):
desk = QtWidgets.QDesktopWidget()
self.xfactor = desk.width()/1600.0;
self.yfactor = desk.height()/900.0;
print(self.xfactor)
def setupobject(self):
self.windetails.append((int)(1130 * self.xfactor))
self.windetails.append((int)(732 * self.yfactor))
self.windetails.append((int)(470 * self.xfactor))
self.windetails.append((int)(160 * self.yfactor))
pepwin_ = pepwin(self)
pepwin_.setupwindow(self.windetails,self.xfactor,self.yfactor)
pepwin_.setbtncnfg(3,3,self.windetails[2], self.windetails[3])
pepwin_.settext(1,1,"Select\nFiles")
pepwin_.settext(3, 3, "Exit")
pepwin_.show()
self.windetails.clear()
self.windetails.append(0.0)
self.windetails.append(0.0)
self.windetails.append(1600.0 * self.xfactor)
self.windetails.append(50.0 * self.yfactor)
scrntitle_ = screentitle(self)
scrntitle_.setupwindow(self.windetails, self.xfactor, self.yfactor)
scrntitle_.show()
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
window = Mainwindow()
window.setStyleSheet("background-color:black")
window.showFullScreen()
sys.exit(app.exec_())
Upvotes: 0
Views: 253
Reputation: 24420
From the official documentation of QDesktopWidget
:
Screen Geometry
To obtain the dimensions of a particular screen, call the screenGeometry() function. On some desktop environments, not all of the screen is available for applications to use; for example, an application dock or menu bar may take up some space. Use the availableGeometry() function to obtain the available area for applications.
QDesktopWidget also inherits the QWidget properties, width() and height(), which specify the size of the desktop. However, for desktops with multiple screens, the size of the desktop is the union of all the screen sizes, so width() and height() should not be used for computing the size of a widget to be placed on one of the screens.
So instead of scaling the geometry of your widgets with desk.width()
and desk.height()
you should be scaling it with desk.screenGeometry().width()
and desk.screenGeometry().height()
.
Upvotes: 0
Reputation: 243955
When a widget is the son of a window, it is placed on top of it, in your case the second widget is placed on top of the first one. If you want to show both widgets should not overlap, a possible solution is to use a layout set in the centralwidget
# ...
def setupobject(self):
self.windetails = [
int(1130 * self.xfactor),
int(732 * self.yfactor),
int(470 * self.xfactor),
int(160 * self.yfactor),
]
pepwin_ = pepwin(self)
pepwin_.setupwindow(self.windetails, self.xfactor, self.yfactor)
pepwin_.setbtncnfg(3, 3, self.windetails[2], self.windetails[3])
pepwin_.settext(1, 1, "Select\nFiles")
pepwin_.settext(3, 3, "Exit")
self.windetails = [0, 0, 1600.0 * self.xfactor, 50.0 * self.yfactor]
scrntitle_ = screentitle(self)
scrntitle_.setuowindow(self.windetails, self.xfactor, self.yfactor)
centralwidget = QtWidgets.QWidget()
self.setCentralWidget(centralwidget)
lay = QtWidgets.QVBoxLayout(centralwidget)
lay.addWidget(pepwin_)
lay.addWidget(scrntitle_)
# ...
Upvotes: 2