I'm creating a screen with StackWidget consist of 3 pages.
The problem is that only one page of the stackwidget pages showing all widgets inside it but the other pages cutting three element in the corners, see the photos
the error page:
correct page and i want the other pages show all widgets in the four corners :
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1200, 679)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(30, 100, 93, 28))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_2.setGeometry(QtCore.QRect(30, 220, 93, 28))
self.pushButton_2.setObjectName("pushButton_2")
self.pushButton_3 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_3.setGeometry(QtCore.QRect(30, 330, 93, 28))
self.pushButton_3.setObjectName("pushButton_3")
self.stackedWidget = QtWidgets.QStackedWidget(self.centralwidget)
self.stackedWidget.setGeometry(QtCore.QRect(170, 0, 1011, 631))
self.stackedWidget.setObjectName("stackedWidget")
self.page_3 = QtWidgets.QWidget()
self.page_3.setObjectName("page_3")
self.pushButton_4 = QtWidgets.QPushButton(self.page_3)
self.pushButton_4.setGeometry(QtCore.QRect(10, 10, 93, 28))
self.pushButton_4.setObjectName("pushButton_4")
self.pushButton_5 = QtWidgets.QPushButton(self.page_3)
self.pushButton_5.setGeometry(QtCore.QRect(880, 20, 93, 28))
self.pushButton_5.setObjectName("pushButton_5")
self.pushButton_6 = QtWidgets.QPushButton(self.page_3)
self.pushButton_6.setGeometry(QtCore.QRect(10, 580, 93, 28))
self.pushButton_6.setObjectName("pushButton_6")
self.pushButton_7 = QtWidgets.QPushButton(self.page_3)
self.pushButton_7.setGeometry(QtCore.QRect(890, 590, 93, 28))
self.pushButton_7.setObjectName("pushButton_7")
self.stackedWidget.addWidget(self.page_3)
self.page_4 = QtWidgets.QWidget()
self.page_4.setObjectName("page_4")
self.lineEdit = QtWidgets.QLineEdit(self.page_4)
self.lineEdit.setGeometry(QtCore.QRect(10, 30, 113, 22))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.page_4)
self.lineEdit_2.setGeometry(QtCore.QRect(870, 580, 113, 22))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtWidgets.QLineEdit(self.page_4)
self.lineEdit_3.setGeometry(QtCore.QRect(30, 570, 113, 22))
self.lineEdit_3.setObjectName("lineEdit_3")
self.lineEdit_4 = QtWidgets.QLineEdit(self.page_4)
self.lineEdit_4.setGeometry(QtCore.QRect(860, 30, 113, 22))
self.lineEdit_4.setObjectName("lineEdit_4")
self.stackedWidget.addWidget(self.page_4)
self.page_5 = QtWidgets.QWidget()
self.page_5.setObjectName("page_5")
self.calendarWidget = QtWidgets.QCalendarWidget(self.page_5)
self.calendarWidget.setGeometry(QtCore.QRect(10, 10, 392, 236))
self.calendarWidget.setObjectName("calendarWidget")
self.calendarWidget_2 = QtWidgets.QCalendarWidget(self.page_5)
self.calendarWidget_2.setGeometry(QtCore.QRect(600, 20, 392, 236))
self.calendarWidget_2.setObjectName("calendarWidget_2")
self.calendarWidget_3 = QtWidgets.QCalendarWidget(self.page_5)
self.calendarWidget_3.setGeometry(QtCore.QRect(610, 380, 392, 236))
self.calendarWidget_3.setObjectName("calendarWidget_3")
self.calendarWidget_4 = QtWidgets.QCalendarWidget(self.page_5)
self.calendarWidget_4.setGeometry(QtCore.QRect(10, 380, 392, 236))
self.calendarWidget_4.setObjectName("calendarWidget_4")
self.stackedWidget.addWidget(self.page_5)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1200, 26))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
self.stackedWidget.setCurrentIndex(2)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "1"))
self.pushButton_2.setText(_translate("MainWindow", "2"))
self.pushButton_3.setText(_translate("MainWindow", "3"))
self.pushButton_4.setText(_translate("MainWindow", "PushButton"))
self.pushButton_5.setText(_translate("MainWindow", "PushButton"))
self.pushButton_6.setText(_translate("MainWindow", "PushButton"))
self.pushButton_7.setText(_translate("MainWindow", "PushButton"))
Blockquote
import sys
from PyQt5.QtWidgets import QMainWindow, QApplication, QAction ,QFileDialog
from stackwidgettest import *
class MyForm(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.ui.pushButton.clicked.connect(self.moveforward)
self.ui.pushButton_2.clicked.connect(self.moveback)
self.ui.pushButton_3.clicked.connect(self.movebacks)
def moveforward(self):
self.ui.page_3.show()
self.ui.page_4.hide()
self.ui.page_5.hide()
def moveback(self):
self.ui.page_3.hide()
self.ui.page_4.show()
self.ui.page_5.hide()
def movebacks(self):
self.ui.page_3.hide()
self.ui.page_4.hide()
self.ui.page_5.show()
if __name__=="__main__":
app = QApplication(sys.argv)
w = MyForm()
w.show()
sys.exit(app.exec_())
The problem solved by setCurrentIndex() method for the stackwidget
Related
I tried install all rquired libsI tried install all rquired libs and Im so sorry I am new here,Im trying to show datas in database on that widget and this problem occurs,I searched all others about that but could not find any issue
import sys
from PyQt5.uic import loadUi
from PyQt5 import QtCore, QtGui, QtWidgets
import mysql.connector
from PyQt5.QtWidgets import QDialog , QApplication , QLineEdit , QInputDialog
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.tableWidget = QtWidgets.QTableWidget(self.centralwidget)
self.tableWidget.setGeometry(QtCore.QRect(60, 0, 721, 300))
self.tableWidget.setObjectName("tableWidget")
self.tableWidget.setColumnCount(7)
self.tableWidget.setRowCount(0)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(1, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(2, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(3, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(4, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(5, item)
item = QtWidgets.QTableWidgetItem()
self.tableWidget.setHorizontalHeaderItem(6, item)
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(60, 300, 133, 20))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(60, 320, 133, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(60, 340, 133, 20))
self.lineEdit_3.setObjectName("lineEdit_3")
self.lineEdit_4 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_4.setGeometry(QtCore.QRect(60, 360, 133, 20))
self.lineEdit_4.setObjectName("lineEdit_4")
self.lineEdit_5 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_5.setGeometry(QtCore.QRect(60, 380, 133, 20))
self.lineEdit_5.setObjectName("lineEdit_5")
self.lineEdit_6 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_6.setGeometry(QtCore.QRect(60, 400, 133, 20))
self.lineEdit_6.setObjectName("lineEdit_6")
self.pushButton = QtWidgets.QPushButton(self.centralwidget,clicked=lambda:self.save())
self.pushButton.setGeometry(QtCore.QRect(193, 300, 91, 121))
self.pushButton.setObjectName("pushButton")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(290, 300, 47, 20))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(290, 320, 47, 20))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(290, 340, 47, 20))
self.label_3.setObjectName("label_3")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(290, 360, 47, 20))
self.label_4.setObjectName("label_4")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(290, 380, 47, 20))
self.label_5.setObjectName("label_5")
self.label_6 = QtWidgets.QLabel(self.centralwidget)
self.label_6.setGeometry(QtCore.QRect(290, 400, 47, 20))
self.label_6.setObjectName("label_6")
self.lineEdit_7 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_7.setGeometry(QtCore.QRect(330, 320, 133, 20))
self.lineEdit_7.setObjectName("lineEdit_7")
self.lineEdit_8 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_8.setGeometry(QtCore.QRect(330, 360, 133, 20))
self.lineEdit_8.setObjectName("lineEdit_8")
self.lineEdit_9 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_9.setGeometry(QtCore.QRect(330, 380, 133, 20))
self.lineEdit_9.setObjectName("lineEdit_9")
self.lineEdit_10 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_10.setGeometry(QtCore.QRect(330, 400, 133, 20))
self.lineEdit_10.setObjectName("lineEdit_10")
self.pushButton_2 = QtWidgets.QPushButton(self.centralwidget,clicked=lambda:self.edit())
self.pushButton_2.setGeometry(QtCore.QRect(460, 300, 91, 121))
self.pushButton_2.setObjectName("pushButton_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
item = self.tableWidget.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "sayı"))
item = self.tableWidget.horizontalHeaderItem(1)
item.setText(_translate("MainWindow", "merkez"))
item = self.tableWidget.horizontalHeaderItem(2)
item.setText(_translate("MainWindow", "sayac no"))
item = self.tableWidget.horizontalHeaderItem(3)
item.setText(_translate("MainWindow", "geliş"))
item = self.tableWidget.horizontalHeaderItem(4)
item.setText(_translate("MainWindow", "çıkış"))
item = self.tableWidget.horizontalHeaderItem(5)
item.setText(_translate("MainWindow", "fiyat-geliş"))
item = self.tableWidget.horizontalHeaderItem(6)
item.setText(_translate("MainWindow", "fiyat-çıkış"))
self.pushButton.setText(_translate("MainWindow", "PushButton"))
self.label.setText(_translate("MainWindow", "MERKEZ"))
self.label_2.setText(_translate("MainWindow", "SAYAC"))
self.label_3.setText(_translate("MainWindow", "GELİŞ"))
self.label_4.setText(_translate("MainWindow", "ÇIKIŞ"))
self.label_5.setText(_translate("MainWindow", "GELİŞ-F"))
self.label_6.setText(_translate("MainWindow", "ÇIKIŞ-F"))
self.pushButton_2.setText(_translate("MainWindow", "PushButton"))
def save(self):
mydb=mysql.connector.connect(
host="localhost",
user="root",
password="Tu41893982790",
database="deneme")
mycursor=mydb.cursor()
sql="INSERT INTO sayac(merkez,sayac_no,gelis_tarihi,cikis_tarihi,gelis_fiyati,cikis_fiyati) VALUES(%s,%s,%s,%s,%s,%s)"
val=(str(self.lineEdit.text()),str(self.lineEdit_2.text()),str(self.lineEdit_3.text()),str(self.lineEdit_4.text()),str(self.lineEdit_5.text()),str(self.lineEdit_6.text()))
mycursor.execute(sql,val)
mydb.commit()
def edit(self):
mydb=mysql.connector.connect(
host="localhost",
user="root",
password="Tu41893982790",
database="deneme")
mycursor=mydb.cursor()
sql=f"UPDATE sayac SET cikis_tarihi={self.lineEdit_8.text()},gelis_fiyati={self.lineEdit_9.text()},cikis_fiyati={self.lineEdit_10.text()} WHERE sayac_no={self.lineEdit_7.text()}"
mycursor.execute(sql)
mydb.commit()
def load_data(self):
mydb=mysql.connector.connect(
host="localhost",
user="root",
password="Tu41893982790",
database="deneme")
mycursor=mydb.cursor()
sql="SELECT * FROM sayac"
mycursor.execute(sql)
results=mycursor.fetchall()
results.reverse()
results=list(results)
row=0
for sayac in results:
self.tableWidget.setItem(row,0,QtWidgets,QTableWidgetItem(sayac[0]))
self.tableWidget.setItem(row,1,QtWidgets,QTableWidgetItem(sayac[1]))
self.tableWidget.setItem(row,2,QtWidgets,QTableWidgetItem(sayac[2]))
self.tableWidget.setItem(row,3,QtWidgets,QTableWidgetItem(sayac[3]))
self.tableWidget.setItem(row,4,QtWidgets,QTableWidgetItem(sayac[4]))
self.tableWidget.setItem(row,5,QtWidgets,QTableWidgetItem(sayac[5]))
self.tableWidget.setItem(row,6,QtWidgets,QTableWidgetItem(sayac[6]))
row+=1
if name == "main":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
I have noticed that this problem occurs because of 'for sayac in results:' when it is removed,no problem but ı need this loop
I am trying to add some check boxes in scroll area.but for me it is not working properly.i am new in python could anyone help?
import PyQt5
from PyQt5 import QtCore, QtGui, QtWidgets
from configparser import ConfigParser
import paramiko
import threading
import os
if hasattr(QtCore.Qt, 'AA_EnableHighDpiScaling'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_EnableHighDpiScaling, True)
if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
PyQt5.QtWidgets.QApplication.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps, True)
class Ui_MainWindow(object):
def __init__(self, parent=None):
self.configur = ConfigParser()
self.configur.read('ServerConfigurationDetails.ini')
self.serverName=self.configur.sections()
print(self.serverName)
self.getComponents = self.configur.options("Component")
self.sLen = len(self.serverName)
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setEnabled(True)
MainWindow.resize(951, 634)
font = QtGui.QFont()
font.setPointSize(10)
MainWindow.setFont(font)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(150, 220, 91, 31))
font = QtGui.QFont()
font.setPointSize(14)
self.label_2.setFont(font)
self.label_2.setObjectName("label_2")
self.comboBox_2 = QtWidgets.QComboBox(self.centralwidget)
self.comboBox_2.setGeometry(QtCore.QRect(250, 220, 231, 31))
self.comboBox_2.setObjectName("comboBox_2")
self.comboBox_2.addItem("")
self.comboBox_2.addItem("")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(700, 40, 101, 31))
self.pushButton.setObjectName("pushButton")
self.groupBox = QtWidgets.QGroupBox(self.centralwidget)
self.groupBox.setGeometry(QtCore.QRect(140, 260, 681, 81))
self.groupBox.setObjectName("groupBox")
self.radioButton = QtWidgets.QRadioButton(self.groupBox)
self.radioButton.setGeometry(QtCore.QRect(10, 30, 201, 20))
self.radioButton.setObjectName("radioButton")
self.radioButton_2 = QtWidgets.QRadioButton(self.groupBox)
self.radioButton_2.setGeometry(QtCore.QRect(220, 30, 201, 20))
self.radioButton_2.setObjectName("radioButton_2")
self.checkBox = QtWidgets.QCheckBox(self.groupBox)
self.checkBox.setEnabled(False)
self.checkBox.setGeometry(QtCore.QRect(10, 50, 231, 31))
self.checkBox.setChecked(True)
self.checkBox.setObjectName("checkBox")
self.radioButton_3 = QtWidgets.QRadioButton(self.groupBox)
self.radioButton_3.setGeometry(QtCore.QRect(420, 30, 171, 20))
self.radioButton_3.setObjectName("radioButton_3")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(280, 40, 411, 31))
self.lineEdit.setObjectName("lineEdit")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(130, 40, 131, 31))
self.label_3.setObjectName("label_3")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(140, 125, 661, 21))
self.label_5.setText("")
self.label_5.setObjectName("label_5")
self.scrollArea = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea.setGeometry(QtCore.QRect(130, 110, 681, 101))
self.scrollArea.setAccessibleDescription("")
self.scrollArea.setWidgetResizable(False)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QtWidgets.QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 679, 99))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
c=10
n=0
x = 10
y = 10
print(self.sLen)
for i in range(self.sLen):
if(n==4):
n=0
x=10
y=y+20
self.checkbox1 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
self.checkbox1.setGeometry(QtCore.QRect(x+1, y+1, 161, 20))
self.checkbox1.setText(self.serverName[i])
self.checkbox1.setObjectName(self.serverName[i])
print(x)
print(n)
n=n+1
if(n==4):
x=10
y = y+20
else:
x= x+180
## self.checkBox_2 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
## self.checkBox_2.setGeometry(QtCore.QRect(10, 10, 161, 20))
## self.checkBox_2.setObjectName("checkBox_2")
## self.checkBox_3 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
## self.checkBox_3.setGeometry(QtCore.QRect(180, 10, 131, 20))
## self.checkBox_3.setObjectName("checkBox_3")
## self.checkBox_4 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
## self.checkBox_4.setGeometry(QtCore.QRect(350, 10, 151, 20))
## self.checkBox_4.setObjectName("checkBox_4")
## self.checkBox_5 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
## self.checkBox_5.setGeometry(QtCore.QRect(530, 10, 141, 20))
## self.checkBox_5.setObjectName("checkBox_5")
## self.checkBox_6 = QtWidgets.QCheckBox(self.scrollAreaWidgetContents)
## self.checkBox_6.setGeometry(QtCore.QRect(10, 30, 161, 20))
## self.checkBox_6.setObjectName("checkBox_6")
self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAsNeeded)
self.scrollArea.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.scrollArea_2 = QtWidgets.QScrollArea(self.centralwidget)
self.scrollArea_2.setGeometry(QtCore.QRect(140, 380, 681, 191))
self.scrollArea_2.setWidgetResizable(True)
self.scrollArea_2.setObjectName("scrollArea_2")
self.scrollAreaWidgetContents_2 = QtWidgets.QWidget()
self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, 0, 679, 189))
self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
self.scrollArea_2.setWidget(self.scrollAreaWidgetContents_2)
self.line = QtWidgets.QFrame(self.centralwidget)
self.line.setGeometry(QtCore.QRect(70, 340, 811, 20))
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
MainWindow.setCentralWidget(self.centralwidget)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 951, 26))
self.menubar.setObjectName("menubar")
self.menuhelp = QtWidgets.QMenu(self.menubar)
self.menuhelp.setObjectName("menuhelp")
MainWindow.setMenuBar(self.menubar)
self.actionAbout = QtWidgets.QAction(MainWindow)
self.actionAbout.setObjectName("actionAbout")
self.menuhelp.addAction(self.actionAbout)
self.menubar.addAction(self.menuhelp.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.label_2.setText(_translate("MainWindow", "<html><head/><body><p><span style=\" font-size:10pt;\">Component</span></p></body></html>"))
self.comboBox_2.setItemText(0, _translate("MainWindow", "eComm"))
self.comboBox_2.setItemText(1, _translate("MainWindow", "workproc"))
self.pushButton.setText(_translate("MainWindow", "Search"))
self.groupBox.setTitle(_translate("MainWindow", "Other Details"))
self.radioButton.setText(_translate("MainWindow", "Only Search in Archive"))
self.radioButton_2.setText(_translate("MainWindow", "Also Search in Archive"))
self.checkBox.setText(_translate("MainWindow", "Auto Download"))
self.radioButton_3.setText(_translate("MainWindow", "Only Search in Log"))
self.label_3.setText(_translate("MainWindow", "<html><head/><body><p>Search String<span style=\" color:#ff0000;\">*</span></p></body></html>"))
## self.checkBox_2.setText(_translate("MainWindow", "CheckBox"))
## self.checkBox_3.setText(_translate("MainWindow", "CheckBox"))
## self.checkBox_4.setText(_translate("MainWindow", "CheckBox"))
## self.checkBox_5.setText(_translate("MainWindow", "CheckBox"))
## self.checkBox_6.setText(_translate("MainWindow", "CheckBox"))
self.menuhelp.setTitle(_translate("MainWindow", "Help"))
self.actionAbout.setText(_translate("MainWindow", "About"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
as you can see the scroll area is not showing properly.i have some 20 servers to show.this server list is coming from ini file and i need to show the check boxes in that scroll area.
you need to use QLayout to arrange you widgets. check out
Qt Designer -> "Widget Box" docker -> "Layouts" section
For the scrollarea part:
create scrollarea scroll_area = QScrollArea()
create view widget you want to put inside scrollarea base_widget = QWidget()
install view layout for view widget base_layout = QVBoxLayout(base_widget)
install view widget into scrollarea scroll_area.setWidget(base_widget)
fill in objects with view layout base_layout.addWidget(QLabel('foo')) base_layout.addWidget(QPushButton('bar')) base_layout.addLayout(my_sub_layout) etc.
i have a python file which is designed using pyqt5 designer, i have .xml file which is the expected output, in this .xml file, there is spaces which will be replaced according to the desired input values?
like this, address will be in address location.
Here is my kuthi.py code:
# -*- coding: utf-8 -*-
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(800, 600)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.pushButton = QtWidgets.QPushButton(self.centralwidget)
self.pushButton.setGeometry(QtCore.QRect(190, 330, 75, 23))
self.pushButton.setObjectName("pushButton")
self.lineEdit_3 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_3.setGeometry(QtCore.QRect(200, 190, 261, 20))
self.lineEdit_3.setObjectName("lineEdit_3")
self.dateEdit = QtWidgets.QDateEdit(self.centralwidget)
self.dateEdit.setGeometry(QtCore.QRect(200, 260, 111, 22))
self.dateEdit.setObjectName("dateEdit")
self.label_4 = QtWidgets.QLabel(self.centralwidget)
self.label_4.setGeometry(QtCore.QRect(80, 230, 101, 16))
self.label_4.setObjectName("label_4")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(80, 170, 111, 16))
self.label_2.setObjectName("label_2")
self.lineEdit_4 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_4.setGeometry(QtCore.QRect(200, 230, 261, 20))
self.lineEdit_4.setObjectName("lineEdit_4")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(80, 130, 81, 16))
self.label.setObjectName("label")
self.lineEdit = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit.setGeometry(QtCore.QRect(200, 130, 261, 20))
self.lineEdit.setObjectName("lineEdit")
self.label_5 = QtWidgets.QLabel(self.centralwidget)
self.label_5.setGeometry(QtCore.QRect(80, 260, 111, 16))
self.label_5.setObjectName("label_5")
self.label_3 = QtWidgets.QLabel(self.centralwidget)
self.label_3.setGeometry(QtCore.QRect(80, 200, 111, 16))
self.label_3.setObjectName("label_3")
self.lineEdit_2 = QtWidgets.QLineEdit(self.centralwidget)
self.lineEdit_2.setGeometry(QtCore.QRect(200, 160, 261, 20))
self.lineEdit_2.setObjectName("lineEdit_2")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 800, 21))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.pushButton.setText(_translate("MainWindow", "Submit"))
self.label_4.setText(_translate("MainWindow", "Enter Address :"))
self.label_2.setText(_translate("MainWindow", "Enter Father\'s Name :"))
self.label.setText(_translate("MainWindow", "Enter Full Name :"))
self.label_5.setText(_translate("MainWindow", "Enter Date of Birth :"))
self.label_3.setText(_translate("MainWindow", "Enter Mother\'s Name :"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
I'm building restaurant app for practice with PyQt5 i have 2 problems:
I have a main screen that will take the user to other screens
when changing between screens in the second time i get error and it crash
The previous window won't close when i'm moving to the new window so every time it's new window
I tried searching for information about it and all i can find is how to do things in the same screen not in a new screen
Code for you to see yourself:
first screen:
from mainMenu import*
from PyQt5 import QtCore, QtGui, QtWidgets
mod=0#0 - TA , 1- Delivery
class Ui_Main():
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1072, 747)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.ta = QtWidgets.QPushButton(self.centralwidget)
self.ta.setGeometry(QtCore.QRect(680, 50, 191, 171))
self.ta.setObjectName("ta")
self.ta.clicked.connect(self.taClicked)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1072, 22))
self.menubar.setObjectName("menubar")
self.menuMain = QtWidgets.QMenu(self.menubar)
self.menuMain.setObjectName("menuMain")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.menubar.addAction(self.menuMain.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow",
"MainWindow"))
self.ta.setText(_translate("MainWindow", "TA"))
self.menuMain.setTitle(_translate("MainWindow", "Main"))
def taClicked(self):
mod=0
print("here")
self.window = QtWidgets.QMainWindow()
self.ui = Ui_MainMenu() # ------------->creating an object
self.ui.setupUi(self.window)
self.window.show()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_Main()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Second screen:
import sys
from PyQt5 import QtCore, QtGui, QtWidgets
from main import*
class Ui_MainMenu(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1073, 738)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.graphicsView = QtWidgets.QGraphicsView(self.centralwidget)
self.graphicsView.setGeometry(QtCore.QRect(685, 40, 331, 251))
self.graphicsView.setObjectName("graphicsView")
self.line = QtWidgets.QFrame(self.centralwidget)
self.line.setGeometry(QtCore.QRect(80, 330, 561, 20))
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(190, 385, 71, 41))
self.label.setObjectName("label")
self.pushButton_14 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_14.setGeometry(QtCore.QRect(190, 440, 81, 51))
self.pushButton_14.setObjectName("pushButton_14")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(800, 380, 81, 16))
self.label_2.setObjectName("label_2")
self.spinBox = QtWidgets.QSpinBox(self.centralwidget)
self.spinBox.setGeometry(QtCore.QRect(727, 370, 61, 41))
self.spinBox.setObjectName("spinBox")
self.pushButton_40 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_40.setGeometry(QtCore.QRect(750, 600, 141, 41))
self.pushButton_40.setObjectName("pushButton_40")
self.pushButton_40.clicked.connect(self.btnclicked)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1073, 22))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainMenu", "MainMenu"))
self.pushButton_40.setText(_translate("MainWindow", "Cancel"))
def btnclicked(self):
print("here")
self.window = QtWidgets.QMainWindow()
self.m= Ui_Main()
self.m.setupUi(self.window)
self.window.show()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QMainWindow()
ui = Ui_MainMenu()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())
Error:
Traceback (most recent call last):
File "/Users/adir/PycharmProjects/main.py", line 61, in taClicked
self.ui = Ui_MainMenu() # ------------->creating an object
NameError: name 'Ui_MainMenu' is not defined
Try it:
#from mainMenu import*
from PyQt5 import QtCore, QtGui, QtWidgets
mod = 0 #0 - TA , 1- Delivery
class Ui_MainMenu(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1073, 738)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.graphicsView = QtWidgets.QGraphicsView(self.centralwidget)
self.graphicsView.setGeometry(QtCore.QRect(685, 40, 331, 251))
self.graphicsView.setObjectName("graphicsView")
self.line = QtWidgets.QFrame(self.centralwidget)
self.line.setGeometry(QtCore.QRect(80, 330, 561, 20))
self.line.setFrameShape(QtWidgets.QFrame.HLine)
self.line.setFrameShadow(QtWidgets.QFrame.Sunken)
self.line.setObjectName("line")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(190, 385, 71, 41))
self.label.setObjectName("label")
self.pushButton_14 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_14.setGeometry(QtCore.QRect(190, 440, 81, 51))
self.pushButton_14.setObjectName("pushButton_14")
self.label_2 = QtWidgets.QLabel(self.centralwidget)
self.label_2.setGeometry(QtCore.QRect(800, 380, 81, 16))
self.label_2.setObjectName("label_2")
self.spinBox = QtWidgets.QSpinBox(self.centralwidget)
self.spinBox.setGeometry(QtCore.QRect(727, 370, 61, 41))
self.spinBox.setObjectName("spinBox")
self.pushButton_40 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_40.setGeometry(QtCore.QRect(750, 600, 141, 41))
self.pushButton_40.setObjectName("pushButton_40")
# self.pushButton_40.clicked.connect(self.btnclicked)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1073, 22))
self.menubar.setObjectName("menubar")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainMenu", "MainMenu"))
self.pushButton_40.setText(_translate("MainWindow", "Cancel"))
class Ui_Main():
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1072, 747)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.ta = QtWidgets.QPushButton(self.centralwidget)
self.ta.setGeometry(QtCore.QRect(680, 50, 191, 171))
self.ta.setObjectName("ta")
# self.ta.clicked.connect(self.taClicked)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1072, 22))
self.menubar.setObjectName("menubar")
self.menuMain = QtWidgets.QMenu(self.menubar)
self.menuMain.setObjectName("menuMain")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.menubar.addAction(self.menuMain.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow",
"MainWindow"))
self.ta.setText(_translate("MainWindow", "TA"))
self.menuMain.setTitle(_translate("MainWindow", "Main"))
class MainWindow(QtWidgets.QMainWindow, Ui_Main):
def __init__(self):
super().__init__()
self.setupUi(self)
self.ta.clicked.connect(self.taClicked)
def taClicked(self):
mod = 0
print("here")
self.window = QtWidgets.QMainWindow()
self.mainMenu = Ui_MainMenu() # ------------->creating an object
self.mainMenu.setupUi(self.window)
self.mainMenu.pushButton_40.clicked.connect(self.btnclicked)
self.window.show()
self.hide()
def btnclicked(self):
self.window.hide()
self.show()
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
# MainWindow = QtWidgets.QMainWindow()
# ui = Ui_Main()
# ui.setupUi(MainWindow)
# MainWindow.show()
mainWindow = MainWindow()
mainWindow.show()
sys.exit(app.exec_())
I am writing a Weight converter to convert killogram to Pounds and vice versa....
Using QT Desginer I have done the interface etc, but now I am stuck trying to figure out how to link the buttons so that when you press one it converts to pound what is entered and vice versa...
Coding so Far:
# WARNING! All changes made in this file will be lost!
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(486, 406)
self.pushButton = QtWidgets.QPushButton(MainWindow)
self.pushButton.setGeometry(QtCore.QRect(160, 320, 151, 41))
self.pushButton.setObjectName("pushButton")
self.pushButton_2 = QtWidgets.QPushButton(MainWindow)
self.pushButton_2.setGeometry(QtCore.QRect(160, 60, 151, 41))
self.pushButton_2.setObjectName("pushButton_2")
self.label = QtWidgets.QLabel(MainWindow)
self.label.setGeometry(QtCore.QRect(86, 20, 301, 31))
self.label.setObjectName("label")
self.label_2 = QtWidgets.QLabel(MainWindow)
self.label_2.setGeometry(QtCore.QRect(20, 230, 131, 21))
self.label_2.setObjectName("label_2")
self.label_3 = QtWidgets.QLabel(MainWindow)
self.label_3.setGeometry(QtCore.QRect(350, 230, 111, 21))
self.label_3.setObjectName("label_3")
self.lineEdit = QtWidgets.QLineEdit(MainWindow)
self.lineEdit.setGeometry(QtCore.QRect(20, 170, 113, 41))
self.lineEdit.setObjectName("lineEdit")
self.lineEdit_2 = QtWidgets.QLineEdit(MainWindow)
self.lineEdit_2.setGeometry(QtCore.QRect(340, 170, 113, 41))
self.lineEdit_2.setObjectName("lineEdit_2")
self.label_4 = QtWidgets.QLabel(MainWindow)
self.label_4.setGeometry(QtCore.QRect(10, 60, 441, 311))
self.label_4.setToolTipDuration(2)
self.label_4.setText("leh")
self.label_4.setPixmap(QtGui.QPixmap("../../../../../Desktop/unbalanced-
scale.png"))
self.label_4.setIndent(-4)
self.label_4.setObjectName("label_4")
self.label_4.raise_()
self.pushButton.raise_()
self.pushButton_2.raise_()
self.label.raise_()
self.label_2.raise_()
self.label_3.raise_()
self.lineEdit.raise_()
self.lineEdit_2.raise_()
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Main Window"))
self.pushButton.setText(_translate("MainWindow", "<<< Pounds to Killogram"))
self.pushButton_2.setText(_translate("MainWindow", "Killogram to Pounds >>>"))
self.label.setText(_translate("MainWindow", " Welcom to PJ Nothnagel\'s Weight Converter!"))
self.label_2.setText(_translate("MainWindow", " Killograms"))
self.label_3.setText(_translate("MainWindow", " Pounds"))
if __name__ == "__main__":
import sys
app = QtWidgets.QApplication(sys.argv)
MainWindow = QtWidgets.QDialog()
ui = Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())