PyQt: layout cuts off part of widget edges [closed] - python

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
I'm trying to make a layout for my app. I designed it in Qt Designer, and in the preview everything looks right. But when I run the code, the progress bar sides are cut off.
I guess I need to play with size-policy or something? Here is the actual code (the progress bar is RoundPrg1):
def setupUi(self, MainWindow):
MainWindow.setObjectName(_fromUtf8("MainWindow"))
MainWindow.resize(800, 600)
self.centralwidget = QtGui.QWidget(MainWindow)
self.centralwidget.setObjectName(_fromUtf8("centralwidget"))
self.gridLayout_2 = QtGui.QGridLayout(self.centralwidget)
self.gridLayout_2.setObjectName(_fromUtf8("gridLayout_2"))
self.gridLayout = QtGui.QGridLayout()
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.MainVarsLayout = QtGui.QHBoxLayout()
self.MainVarsLayout.setSizeConstraint(QtGui.QLayout.SetDefaultConstraint)
self.MainVarsLayout.setMargin(10)
self.MainVarsLayout.setSpacing(10)
self.MainVarsLayout.setObjectName(_fromUtf8("MainVarsLayout"))
#self.speedBarplace = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(2)
#sizePolicy.setHeightForWidth(self.speedBarplace.sizePolicy().hasHeightForWidth())
#self.speedBarplace.setSizePolicy(sizePolicy)
#self.speedBarplace.setMinimumSize(QtCore.QSize(300, 270))
#self.speedBarplace.setObjectName(_fromUtf8("speedBarplace"))
self.MainVarsLayout.addWidget(self.RoundPrg)#(self.speedBarplace)
self.MainVariablesLayout = QtGui.QVBoxLayout()
self.MainVariablesLayout.setObjectName(_fromUtf8("MainVariablesLayout"))
self.temperaturePlace = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(2)
sizePolicy.setHeightForWidth(self.temperaturePlace.sizePolicy().hasHeightForWidth())
self.temperaturePlace.setSizePolicy(sizePolicy)
self.temperaturePlace.setMinimumSize(QtCore.QSize(0, 130))
self.temperaturePlace.setObjectName(_fromUtf8("temperaturePlace"))
self.MainVariablesLayout.addWidget(self.temperaturePlace)
self.fuelPlace = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(2)
sizePolicy.setHeightForWidth(self.fuelPlace.sizePolicy().hasHeightForWidth())
self.fuelPlace.setSizePolicy(sizePolicy)
self.fuelPlace.setMinimumSize(QtCore.QSize(0, 130))
self.fuelPlace.setObjectName(_fromUtf8("fuelPlace"))
self.MainVariablesLayout.addWidget(self.fuelPlace)
self.MainVarsLayout.addLayout(self.MainVariablesLayout)
#self.rpmPlace = QtGui.QPushButton(self.centralwidget)
#sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum)
#sizePolicy.setHorizontalStretch(0)
#sizePolicy.setVerticalStretch(2)
#sizePolicy.setHeightForWidth(self.rpmPlace.sizePolicy().hasHeightForWidth())
#self.rpmPlace.setSizePolicy(sizePolicy)
#self.rpmPlace.setMinimumSize(QtCore.QSize(300, 270))
#self.rpmPlace.setObjectName(_fromUtf8("rpmPlace"))
self.MainVarsLayout.addWidget(self.RoundPrg2)#(self.rpmPlace)
self.gridLayout.addLayout(self.MainVarsLayout, 1, 0, 1, 1)
self.InfoLayout = QtGui.QHBoxLayout()
self.InfoLayout.setSizeConstraint(QtGui.QLayout.SetFixedSize)
self.InfoLayout.setObjectName(_fromUtf8("InfoLayout"))
self.pushButton_2 = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_2.sizePolicy().hasHeightForWidth())
self.pushButton_2.setSizePolicy(sizePolicy)
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.InfoLayout.addWidget(self.pushButton_2)
self.pushButton_3 = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_3.sizePolicy().hasHeightForWidth())
self.pushButton_3.setSizePolicy(sizePolicy)
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.InfoLayout.addWidget(self.pushButton_3)
self.pushButton_4 = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_4.sizePolicy().hasHeightForWidth())
self.pushButton_4.setSizePolicy(sizePolicy)
self.pushButton_4.setObjectName(_fromUtf8("pushButton_4"))
self.InfoLayout.addWidget(self.pushButton_4)
self.pushButton = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton.sizePolicy().hasHeightForWidth())
self.pushButton.setSizePolicy(sizePolicy)
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.InfoLayout.addWidget(self.pushButton)
self.ComputerInfoLayout = QtGui.QVBoxLayout()
self.ComputerInfoLayout.setObjectName(_fromUtf8("ComputerInfoLayout"))
self.PcuTempBar = QtGui.QProgressBar(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.PcuTempBar.sizePolicy().hasHeightForWidth())
self.PcuTempBar.setSizePolicy(sizePolicy)
self.PcuTempBar.setMinimumSize(QtCore.QSize(0, 0))
self.PcuTempBar.setProperty("value", 24)
self.PcuTempBar.setObjectName(_fromUtf8("PcuTempBar"))
self.ComputerInfoLayout.addWidget(self.PcuTempBar)
self.CpuUsageBar = QtGui.QProgressBar(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.CpuUsageBar.sizePolicy().hasHeightForWidth())
self.CpuUsageBar.setSizePolicy(sizePolicy)
self.CpuUsageBar.setMinimumSize(QtCore.QSize(0, 0))
self.CpuUsageBar.setProperty("value", 24)
self.CpuUsageBar.setObjectName(_fromUtf8("CpuUsageBar"))
self.ComputerInfoLayout.addWidget(self.CpuUsageBar)
self.RamUsag[eBar = QtGui.QProgressBar(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.RamUsageBar.sizePolicy().hasHeightForWidth())
self.RamUsageBar.setSizePolicy(sizePolicy)
self.RamUsageBar.setMinimumSize(QtCore.QSize(0, 0))
self.RamUsageBar.setProperty("value", 24)
self.RamUsageBar.setObjectName(_fromUtf8("RamUsageBar"))
self.ComputerInfoLayout.addWidget(self.RamUsageBar)
self.InfoLayout.addLayout(self.ComputerInfoLayout)
self.gridLayout.addLayout(self.InfoLayout, 3, 0, 1, 1)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.pushButton_5 = QtGui.QPushButton(self.centralwidget)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Minimum, QtGui.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_5.sizePolicy().hasHeightForWidth())
self.pushButton_5.setSizePolicy(sizePolicy)
self.pushButton_5.setObjectName(_fromUtf8("pushButton_5"))
self.horizontalLayout.addWidget(self.pushButton_5)
self.gridLayout.addLayout(self.horizontalLayout, 2, 0, 1, 1)
self.gridLayout_2.addLayout(self.gridLayout, 0, 0, 1, 1)
MainWindow.setCentralWidget(self.centralwidget)
Ui file is here
Here is the custom widget .py file

Related

Qt5 QComboBox focusOutEvent

I have built a GUI and among other things I am using a QComboBox (drop-down menu) with three entries. I want to enable/disable some other boxes and labels in the GUI, depending on which entry is selected in the QComboBox. I have managed to do that so far.
My problem is that all changes are taken into effect only when I press the "Run" button, which executes the application.
What I want to do is the action of enabling/disabling the relevant boxes will happen once I have selected the entry from the drop-down menu and not waiting until I press the "Run" button.
Is there a way to do something like that? Can I use the focusOutEvent to check when the user has clicked anywhere else than the drop-menu and apply the changes in the other boxes/labels?
I put below the class "controlling" my GUI, but I dont post the actual class generating the GUI because it is too lengthy. If you think it is relevant I can post it. I post instead a picture of the GUI.GUI The boxes and labels in the black circles should be disabled when the "Measuring Mode" drop-box is set to "Cable loss" or "Amplifier". When it is set to "Mixer" they should be enabled. I enable/disable the boxes and labels with an if statement inside the user_input function, in the Window class. The wanted drop-down menu is represeted by the "mode_select" variable.
Edit:
I think my explanation is not very intuitive without the actual gui code so I post it below.
from PyQt5 import QtWidgets, QtCore
from converter import convert_ui
import sys
import os
import time
class Window(QtWidgets.QMainWindow):
def __init__(self):
from transfer_function_gui import Ui_MainWindow
QtWidgets.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self) # setup GUI
self.ui.run_button_PM_tab.clicked.connect(self.user_input)
def user_input(self):
test_mode = self.ui.mode_select.currentText() # type: str
if test_mode == "Mixer":
self.ui.LO_Power_input.setEnabled(True)
self.ui.LO_Power_lbl.setEnabled(True)
self.ui.LO_freq_input.setEnabled(True)
self.ui.LO_freq_lbl.setEnabled(True)
else:
self.ui.LO_Power_input.setEnabled(False)
self.ui.LO_Power_lbl.setEnabled(False)
self.ui.LO_freq_input.setEnabled(False)
self.ui.LO_freq_lbl.setEnabled(False)
############################### Main ###############################
if __name__=='__main__':
convert_ui('transfer_function_gui.ui')
app = QtWidgets.QApplication(sys.argv)
app.setStyle('Fusion')
window = Window()
window.show()
sys.exit(app.exec_())
GUI generation (from Qt designer)
from PyQt5 import QtCore, QtGui, QtWidgets
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.setEnabled(True)
MainWindow.resize(770, 613)
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.progressBar = QtWidgets.QProgressBar(self.centralwidget)
self.progressBar.setGeometry(QtCore.QRect(10, 520, 630, 30))
self.progressBar.setProperty("value", 0)
self.progressBar.setObjectName("progressBar")
self.Dev_address_frame = QtWidgets.QGroupBox(self.centralwidget)
self.Dev_address_frame.setGeometry(QtCore.QRect(10, 10, 371, 140))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.Dev_address_frame.sizePolicy().hasHeightForWidth())
self.Dev_address_frame.setSizePolicy(sizePolicy)
self.Dev_address_frame.setMinimumSize(QtCore.QSize(0, 100))
font = QtGui.QFont()
font.setPointSize(8)
self.Dev_address_frame.setFont(font)
self.Dev_address_frame.setFlat(False)
self.Dev_address_frame.setCheckable(False)
self.Dev_address_frame.setObjectName("Dev_address_frame")
self.SigGen_label = QtWidgets.QLabel(self.Dev_address_frame)
self.SigGen_label.setGeometry(QtCore.QRect(20, 30, 100, 20))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Maximum, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.SigGen_label.sizePolicy().hasHeightForWidth())
self.SigGen_label.setSizePolicy(sizePolicy)
self.SigGen_label.setObjectName("SigGen_label")
self.PM_label = QtWidgets.QLabel(self.Dev_address_frame)
self.PM_label.setGeometry(QtCore.QRect(20, 70, 100, 20))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.PM_label.sizePolicy().hasHeightForWidth())
self.PM_label.setSizePolicy(sizePolicy)
self.PM_label.setObjectName("PM_label")
self.SigGen_addr_input = QtWidgets.QLineEdit(self.Dev_address_frame)
self.SigGen_addr_input.setGeometry(QtCore.QRect(120, 30, 180, 20))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.SigGen_addr_input.sizePolicy().hasHeightForWidth())
self.SigGen_addr_input.setSizePolicy(sizePolicy)
self.SigGen_addr_input.setObjectName("SigGen_addr_input")
self.PM_addr_input = QtWidgets.QLineEdit(self.Dev_address_frame)
self.PM_addr_input.setGeometry(QtCore.QRect(120, 70, 180, 20))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.PM_addr_input.sizePolicy().hasHeightForWidth())
self.PM_addr_input.setSizePolicy(sizePolicy)
self.PM_addr_input.setObjectName("PM_addr_input")
self.PM_cnct_checkBox = QtWidgets.QCheckBox(self.Dev_address_frame)
self.PM_cnct_checkBox.setEnabled(False)
self.PM_cnct_checkBox.setGeometry(QtCore.QRect(240, 105, 16, 20))
self.PM_cnct_checkBox.setText("")
self.PM_cnct_checkBox.setObjectName("PM_cnct_checkBox")
self.PM_cnct_lbl = QtWidgets.QLabel(self.Dev_address_frame)
self.PM_cnct_lbl.setEnabled(False)
self.PM_cnct_lbl.setGeometry(QtCore.QRect(20, 105, 210, 20))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.PM_cnct_lbl.sizePolicy().hasHeightForWidth())
self.PM_cnct_lbl.setSizePolicy(sizePolicy)
self.PM_cnct_lbl.setObjectName("PM_cnct_lbl")
self.Freq_setup_frame = QtWidgets.QGroupBox(self.centralwidget)
self.Freq_setup_frame.setGeometry(QtCore.QRect(10, 200, 370, 181))
font = QtGui.QFont()
font.setPointSize(8)
self.Freq_setup_frame.setFont(font)
self.Freq_setup_frame.setFlat(False)
self.Freq_setup_frame.setCheckable(False)
self.Freq_setup_frame.setObjectName("Freq_setup_frame")
self.Start_freq_lbl = QtWidgets.QLabel(self.Freq_setup_frame)
self.Start_freq_lbl.setEnabled(True)
self.Start_freq_lbl.setGeometry(QtCore.QRect(20, 30, 100, 20))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.Start_freq_lbl.sizePolicy().hasHeightForWidth())
self.Start_freq_lbl.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setPointSize(8)
self.Start_freq_lbl.setFont(font)
self.Start_freq_lbl.setMidLineWidth(0)
self.Start_freq_lbl.setText("Start freq. ")
self.Start_freq_lbl.setObjectName("Start_freq_lbl")
self.Stop_freq_lbl = QtWidgets.QLabel(self.Freq_setup_frame)
self.Stop_freq_lbl.setGeometry(QtCore.QRect(20, 70, 100, 20))
font = QtGui.QFont()
font.setPointSize(8)
self.Stop_freq_lbl.setFont(font)
self.Stop_freq_lbl.setObjectName("Stop_freq_lbl")
self.Step_freq_lbl = QtWidgets.QLabel(self.Freq_setup_frame)
self.Step_freq_lbl.setGeometry(QtCore.QRect(20, 110, 100, 20))
font = QtGui.QFont()
font.setPointSize(8)
self.Step_freq_lbl.setFont(font)
self.Step_freq_lbl.setObjectName("Step_freq_lbl")
self.StopFreq_input = QtWidgets.QLineEdit(self.Freq_setup_frame)
self.StopFreq_input.setGeometry(QtCore.QRect(120, 70, 180, 20))
font = QtGui.QFont()
font.setPointSize(8)
self.StopFreq_input.setFont(font)
self.StopFreq_input.setText("")
self.StopFreq_input.setObjectName("StopFreq_input")
self.Start_freq_input = QtWidgets.QLineEdit(self.Freq_setup_frame)
self.Start_freq_input.setGeometry(QtCore.QRect(120, 30, 180, 20))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Maximum)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.Start_freq_input.sizePolicy().hasHeightForWidth())
self.Start_freq_input.setSizePolicy(sizePolicy)
font = QtGui.QFont()
font.setPointSize(8)
self.Start_freq_input.setFont(font)
self.Start_freq_input.setText("")
self.Start_freq_input.setObjectName("Start_freq_input")
self.StepFreq_input = QtWidgets.QLineEdit(self.Freq_setup_frame)
self.StepFreq_input.setGeometry(QtCore.QRect(120, 110, 180, 20))
font = QtGui.QFont()
font.setPointSize(8)
self.StepFreq_input.setFont(font)
self.StepFreq_input.setText("")
self.StepFreq_input.setObjectName("StepFreq_input")
self.freq_units_select = QtWidgets.QComboBox(self.Freq_setup_frame)
self.freq_units_select.setGeometry(QtCore.QRect(310, 29, 51, 141))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.freq_units_select.sizePolicy().hasHeightForWidth())
self.freq_units_select.setSizePolicy(sizePolicy)
self.freq_units_select.setMinimumSize(QtCore.QSize(0, 70))
font = QtGui.QFont()
font.setPointSize(8)
self.freq_units_select.setFont(font)
self.freq_units_select.setInsertPolicy(QtWidgets.QComboBox.InsertAtBottom)
self.freq_units_select.setSizeAdjustPolicy(QtWidgets.QComboBox.AdjustToContentsOnFirstShow)
self.freq_units_select.setFrame(True)
self.freq_units_select.setObjectName("freq_units_select")
self.freq_units_select.addItem("")
self.freq_units_select.addItem("")
self.freq_units_select.addItem("")
self.LO_freq_lbl = QtWidgets.QLabel(self.Freq_setup_frame)
self.LO_freq_lbl.setGeometry(QtCore.QRect(20, 150, 100, 20))
font = QtGui.QFont()
font.setPointSize(8)
self.LO_freq_lbl.setFont(font)
self.LO_freq_lbl.setObjectName("LO_freq_lbl")
self.LO_freq_input = QtWidgets.QLineEdit(self.Freq_setup_frame)
self.LO_freq_input.setGeometry(QtCore.QRect(120, 150, 180, 20))
font = QtGui.QFont()
font.setPointSize(8)
self.LO_freq_input.setFont(font)
self.LO_freq_input.setText("")
self.LO_freq_input.setObjectName("LO_freq_input")
self.Power_setup_frame = QtWidgets.QGroupBox(self.centralwidget)
self.Power_setup_frame.setGeometry(QtCore.QRect(10, 390, 370, 111))
font = QtGui.QFont()
font.setPointSize(8)
self.Power_setup_frame.setFont(font)
self.Power_setup_frame.setFlat(False)
self.Power_setup_frame.setCheckable(False)
self.Power_setup_frame.setObjectName("Power_setup_frame")
self.DUT_input_lbl = QtWidgets.QLabel(self.Power_setup_frame)
self.DUT_input_lbl.setGeometry(QtCore.QRect(20, 30, 100, 20))
font = QtGui.QFont()
font.setPointSize(8)
self.DUT_input_lbl.setFont(font)
self.DUT_input_lbl.setObjectName("DUT_input_lbl")
self.LO_Power_lbl = QtWidgets.QLabel(self.Power_setup_frame)
self.LO_Power_lbl.setGeometry(QtCore.QRect(20, 70, 100, 20))
font = QtGui.QFont()
font.setPointSize(8)
self.LO_Power_lbl.setFont(font)
self.LO_Power_lbl.setObjectName("LO_Power_lbl")
self.DUT_Input_power_input = QtWidgets.QLineEdit(self.Power_setup_frame)
self.DUT_Input_power_input.setGeometry(QtCore.QRect(120, 30, 180, 20))
font = QtGui.QFont()
font.setPointSize(8)
self.DUT_Input_power_input.setFont(font)
self.DUT_Input_power_input.setText("")
self.DUT_Input_power_input.setObjectName("DUT_Input_power_input")
self.LO_Power_input = QtWidgets.QLineEdit(self.Power_setup_frame)
self.LO_Power_input.setGeometry(QtCore.QRect(120, 70, 180, 20))
font = QtGui.QFont()
font.setPointSize(8)
self.LO_Power_input.setFont(font)
self.LO_Power_input.setText("")
self.LO_Power_input.setObjectName("LO_Power_input")
self.LO_dBm = QtWidgets.QLabel(self.Power_setup_frame)
self.LO_dBm.setGeometry(QtCore.QRect(320, 70, 20, 20))
font = QtGui.QFont()
font.setPointSize(8)
self.LO_dBm.setFont(font)
self.LO_dBm.setObjectName("LO_dBm")
self.DUT_dBm = QtWidgets.QLabel(self.Power_setup_frame)
self.DUT_dBm.setGeometry(QtCore.QRect(320, 30, 20, 20))
font = QtGui.QFont()
font.setPointSize(8)
self.DUT_dBm.setFont(font)
self.DUT_dBm.setObjectName("DUT_dBm")
self.mode_label = QtWidgets.QLabel(self.centralwidget)
self.mode_label.setGeometry(QtCore.QRect(30, 165, 100, 20))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.mode_label.sizePolicy().hasHeightForWidth())
self.mode_label.setSizePolicy(sizePolicy)
self.mode_label.setBaseSize(QtCore.QSize(0, 0))
self.mode_label.setObjectName("mode_label")
self.mode_select = QtWidgets.QComboBox(self.centralwidget)
self.mode_select.setGeometry(QtCore.QRect(130, 165, 180, 20))
self.mode_select.setObjectName("mode_select")
self.mode_select.addItem("")
self.mode_select.addItem("")
self.mode_select.addItem("")
self.run_button_PM_tab = QtWidgets.QPushButton(self.centralwidget)
self.run_button_PM_tab.setEnabled(True)
self.run_button_PM_tab.setGeometry(QtCore.QRect(650, 520, 100, 30))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.run_button_PM_tab.sizePolicy().hasHeightForWidth())
self.run_button_PM_tab.setSizePolicy(sizePolicy)
self.run_button_PM_tab.setMinimumSize(QtCore.QSize(0, 0))
self.run_button_PM_tab.setLayoutDirection(QtCore.Qt.LeftToRight)
self.run_button_PM_tab.setObjectName("run_button_PM_tab")
self.S21_table = QtWidgets.QTableWidget(self.centralwidget)
self.S21_table.setGeometry(QtCore.QRect(400, 10, 360, 490))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Minimum)
sizePolicy.setHorizontalStretch(33)
sizePolicy.setVerticalStretch(25)
sizePolicy.setHeightForWidth(self.S21_table.sizePolicy().hasHeightForWidth())
self.S21_table.setSizePolicy(sizePolicy)
self.S21_table.setMinimumSize(QtCore.QSize(15, 35))
self.S21_table.setSizeIncrement(QtCore.QSize(0, 0))
self.S21_table.setBaseSize(QtCore.QSize(0, 0))
self.S21_table.setObjectName("S21_table")
self.S21_table.setColumnCount(2)
self.S21_table.setRowCount(1)
item = QtWidgets.QTableWidgetItem()
self.S21_table.setVerticalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
item.setTextAlignment(QtCore.Qt.AlignCenter)
self.S21_table.setHorizontalHeaderItem(0, item)
item = QtWidgets.QTableWidgetItem()
self.S21_table.setHorizontalHeaderItem(1, item)
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 770, 21))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
self.menuAbout = QtWidgets.QMenu(self.menubar)
self.menuAbout.setObjectName("menuAbout")
self.menuPreferences = QtWidgets.QMenu(self.menubar)
self.menuPreferences.setObjectName("menuPreferences")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionSave_as = QtWidgets.QAction(MainWindow)
self.actionSave_as.setObjectName("actionSave_as")
self.actionExit = QtWidgets.QAction(MainWindow)
self.actionExit.setObjectName("actionExit")
self.menuFile.addAction(self.actionSave_as)
self.menuFile.addAction(self.actionExit)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuPreferences.menuAction())
self.menubar.addAction(self.menuAbout.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "Transfer Function Calculator v0.5"))
self.Dev_address_frame.setTitle(_translate("MainWindow", "Device addresses (GPIB, USB, TCPIP)"))
self.SigGen_label.setText(_translate("MainWindow", "Signal Generator"))
self.PM_label.setText(_translate("MainWindow", "Power Meter"))
self.PM_cnct_lbl.setText(_translate("MainWindow", "If PM is connected to SigGen check the box"))
self.Freq_setup_frame.setTitle(_translate("MainWindow", "Frequency setup"))
self.Stop_freq_lbl.setText(_translate("MainWindow", "Stop freq."))
self.Step_freq_lbl.setText(_translate("MainWindow", "Step freq."))
self.freq_units_select.setCurrentText(_translate("MainWindow", "kHz"))
self.freq_units_select.setItemText(0, _translate("MainWindow", "kHz"))
self.freq_units_select.setItemText(1, _translate("MainWindow", "MHz"))
self.freq_units_select.setItemText(2, _translate("MainWindow", "GHz"))
self.LO_freq_lbl.setText(_translate("MainWindow", "LO freq."))
self.Power_setup_frame.setTitle(_translate("MainWindow", "Power setup"))
self.DUT_input_lbl.setText(_translate("MainWindow", "DUT Input power"))
self.LO_Power_lbl.setText(_translate("MainWindow", "LO Power"))
self.LO_dBm.setText(_translate("MainWindow", "dBm"))
self.DUT_dBm.setText(_translate("MainWindow", "dBm"))
self.mode_label.setText(_translate("MainWindow", "Measuring mode"))
self.mode_select.setItemText(0, _translate("MainWindow", "Cable loss"))
self.mode_select.setItemText(1, _translate("MainWindow", "Amplifier"))
self.mode_select.setItemText(2, _translate("MainWindow", "Mixer"))
self.run_button_PM_tab.setText(_translate("MainWindow", "Run"))
item = self.S21_table.verticalHeaderItem(0)
item.setText(_translate("MainWindow", "New Row"))
item = self.S21_table.horizontalHeaderItem(0)
item.setText(_translate("MainWindow", "New Column"))
item = self.S21_table.horizontalHeaderItem(1)
item.setText(_translate("MainWindow", "New Column"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.menuAbout.setTitle(_translate("MainWindow", "About"))
self.menuPreferences.setTitle(_translate("MainWindow", "Settings..."))
self.actionSave_as.setText(_translate("MainWindow", "Save as..."))
self.actionExit.setText(_translate("MainWindow", "Exit"))
QComboBox uses these signals here which you can connect using signals and slots.
I think the one you would want to use is either currentTextChanged or currentIndexChanged. So you could do something like this in your init:
class Window(QtWidgets.QMainWindow):
def __init__(self):
from transfer_function_gui import Ui_MainWindow
QtWidgets.QMainWindow.__init__(self)
self.ui = Ui_MainWindow()
self.ui.setupUi(self) # setup GUI
self.ui.run_button_PM_tab.clicked.connect(self.user_input)
self.ui.freq_units_select.currentIndexChanged.connect(self.user_input)
self.ui.mode_select.currentIndexChanged.connect(self.user_input)
This will connect the event of the QComboBox changing it's selected index to a method called self.user_input.

Open new window in main window pyqt5

I want to design second window opens when button clicked like in image but there are problem I can't understand it
class SubWindow(QWidget):
def __init__(self):
super(SubWindow, self).__init__()
self.resize(673, 349)
sizePolicy = QSizePolicy(QSizePolicy.Ignored,QSizePolicy.Ignored)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.sizePolicy().hasHeightForWidth())
self.setSizePolicy(sizePolicy)
self.setWindowTitle("")
self.centralwidget = QWidget(self)
self.centralwidget.setObjectName("centralwidget")
self.verticalLayout = QVBoxLayout(self.centralwidget)
self.verticalLayout.setObjectName("verticalLayout")
self.scrollArea = QScrollArea(self.centralwidget)
self.scrollArea.setFrameShape(QFrame.NoFrame)
self.scrollArea.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName("scrollArea")
self.scrollAreaWidgetContents = QWidget()
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 638, 331))
self.scrollAreaWidgetContents.setObjectName("scrollAreaWidgetContents")
self.verticalLayout_2 = QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.frame = QFrame(self.scrollAreaWidgetContents)
sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.frame.sizePolicy().hasHeightForWidth())
self.frame.setSizePolicy(sizePolicy)
self.frame.setMinimumSize(QtCore.QSize(0, 100))
self.frame.setStyleSheet("background-color: rgb(71, 71, 71);")
self.frame.setFrameShape(QFrame.StyledPanel)
self.frame.setFrameShadow(QFrame.Raised)
self.frame.setObjectName("frame")
self.horizontalLayout = QHBoxLayout(self.frame)
self.horizontalLayout.setObjectName("horizontalLayout")
self.label = QLabel(self.frame)
sizePolicy = QSizePolicy(QSizePolicy.Fixed, QSizePolicy.Ignored)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
self.label.setSizePolicy(sizePolicy)
self.label.setMinimumSize(QtCore.QSize(100, 0))
self.label.setMaximumSize(QtCore.QSize(0, 100))
self.label.setText("")
self.label.setPixmap(QtGui.QPixmap(r"D:\project(AHR)\WhatsApp Image 2022-03-02 at 8.22.06 PM.jpeg"))
self.label.setScaledContents(True)
self.label.setObjectName("label")
self.horizontalLayout.addWidget(self.label)
self.scrollArea_2 = QScrollArea(self.frame)
self.scrollArea_2.setFrameShape(QFrame.NoFrame)
self.scrollArea_2.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOn)
self.scrollArea_2.setWidgetResizable(True)
self.scrollArea_2.setObjectName("scrollArea_2")
self.scrollAreaWidgetContents_2 = QWidget()
self.scrollAreaWidgetContents_2.setGeometry(QtCore.QRect(0, 0, 494, 63))
self.scrollAreaWidgetContents_2.setObjectName("scrollAreaWidgetContents_2")
self.scrollArea_2.setWidget(self.scrollAreaWidgetContents_2)
self.horizontalLayout.addWidget(self.scrollArea_2)
self.verticalLayout_2.addWidget(self.frame)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout.addWidget(self.scrollArea)
self.setCentralWidget(self)

Style-sheets in PyQt5 bakground-image pushbutton turns it into a no-image pushbutton

I use Qt-Designer to create a mainwindow and used stylesheets to make a button changeimage when pressed. however after running it the background-image and the pressed image does not work.
This is the stylesheet input from Qt-Designer:
QPushButton#House1 {
border-image: url(:/img/Crystal_Clear_app_kfm_home.png);
}
QPushButton#House:pressed {
border-image: url(:/img/Search_in_home.png);
}
This is my mainWindow.py :
from PyQt5 import QtCore, QtGui, QtWidgets
import sys
import resources_rc
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(811, 600)
MainWindow.setStyleSheet("background-color: rgb(211, 211, 211);")
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
###################house 1#######
self.house2 = QtWidgets.QPushButton(self.centralwidget)
self.house1.setGeometry(QtCore.QRect(61, 21, 32, 19))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house1.sizePolicy().hasHeightForWidth())
self.house1.setSizePolicy(sizePolicy)
self.house1.setStyleSheet("#House1 {\n"
"border-image: url(:/img/Crystal_Clear_app_kfm_home.png);\n"
"}\n"
"#House:Pressed {\n"
" border-image: url(:/img/Search_in_home.png);\n"
"}")
self.house1.setText("")
self.house1.setObjectName("house1")
####################end #############
self.house4 = QtWidgets.QPushButton(self.centralwidget)
self.house4.setGeometry(QtCore.QRect(61, 203, 32, 19))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house4.sizePolicy().hasHeightForWidth())
self.house4.setSizePolicy(sizePolicy)
self.house4.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house4.setText("")
self.house4.setObjectName("house4")
self.house2 = QtWidgets.QPushButton(self.centralwidget)
self.house2.setGeometry(QtCore.QRect(293, 21, 32, 19))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house2.sizePolicy().hasHeightForWidth())
self.house2.setSizePolicy(sizePolicy)
self.house2.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house2.setText("")
self.house2.setObjectName("house2")
self.house3 = QtWidgets.QPushButton(self.centralwidget)
self.house3.setGeometry(QtCore.QRect(524, 21, 32, 19))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house3.sizePolicy().hasHeightForWidth())
self.house3.setSizePolicy(sizePolicy)
self.house3.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house3.setText("")
self.house3.setObjectName("house3")
self.pushButton_8 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_8.setGeometry(QtCore.QRect(293, 384, 32, 19))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_8.sizePolicy().hasHeightForWidth())
self.pushButton_8.setSizePolicy(sizePolicy)
self.pushButton_8.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.pushButton_8.setText("")
self.pushButton_8.setObjectName("pushButton_8")
self.house5 = QtWidgets.QPushButton(self.centralwidget)
self.house5.setGeometry(QtCore.QRect(293, 203, 32, 19))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house5.sizePolicy().hasHeightForWidth())
self.house5.setSizePolicy(sizePolicy)
self.house5.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house5.setText("")
self.house5.setObjectName("house5")
self.house6 = QtWidgets.QPushButton(self.centralwidget)
self.house6.setGeometry(QtCore.QRect(524, 203, 32, 19))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house6.sizePolicy().hasHeightForWidth())
self.house6.setSizePolicy(sizePolicy)
self.house6.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house6.setText("")
self.house6.setObjectName("house6")
self.pushButton_7 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_7.setGeometry(QtCore.QRect(61, 384, 32, 19))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_7.sizePolicy().hasHeightForWidth())
self.pushButton_7.setSizePolicy(sizePolicy)
self.pushButton_7.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.pushButton_7.setText("")
self.pushButton_7.setObjectName("pushButton_7")
self.pushButton_9 = QtWidgets.QPushButton(self.centralwidget)
self.pushButton_9.setGeometry(QtCore.QRect(524, 384, 32, 19))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.pushButton_9.sizePolicy().hasHeightForWidth())
self.pushButton_9.setSizePolicy(sizePolicy)
self.pushButton_9.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.pushButton_9.setText("")
self.pushButton_9.setObjectName("pushButton_9")
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 811, 27))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
self.menuAdmin = QtWidgets.QMenu(self.menubar)
self.menuAdmin.setObjectName("menuAdmin")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionOpen = QtWidgets.QAction(MainWindow)
self.actionOpen.setObjectName("actionOpen")
self.actionSave = QtWidgets.QAction(MainWindow)
self.actionSave.setObjectName("actionSave")
self.actionSave_As = QtWidgets.QAction(MainWindow)
self.actionSave_As.setObjectName("actionSave_As")
self.actionLogin = QtWidgets.QAction(MainWindow)
self.actionLogin.setObjectName("actionLogin")
self.actionSign_Up = QtWidgets.QAction(MainWindow)
self.actionSign_Up.setObjectName("actionSign_Up")
self.menuFile.addAction(self.actionOpen)
self.menuFile.addAction(self.actionSave)
self.menuFile.addAction(self.actionSave_As)
self.menuAdmin.addAction(self.actionLogin)
self.menuAdmin.addAction(self.actionSign_Up)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuAdmin.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "SWTDI Main Window"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.menuAdmin.setTitle(_translate("MainWindow", "Admin"))
self.actionOpen.setText(_translate("MainWindow", "Open"))
self.actionSave.setText(_translate("MainWindow", "Save"))
self.actionSave_As.setText(_translate("MainWindow", "Save As"))
self.actionLogin.setText(_translate("MainWindow", "Login"))
self.actionSign_Up.setText(_translate("MainWindow", "Sign Up"))
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(w)
w.show()
sys.exit(app.exec())
resource file:
<!DOCTYPE RCC><RCC version="1.0">
<qresource>
<file>img/house.png</file>
<file>img/house2.png</file>
<file>img/NM_State_University_logo.png</file>
<file>img/NMlogo_1colorstate_black.png</file>
<file>img/NMlogo_1colorstate_red.tif</file>
<file>img/Crystal_Clear_app_kfm_home.png</file>
<file>img/Gohomenew.png</file>
<file>img/Search_in_home.png</file>
</qresource>
</RCC>
The button was created by the line I commented out. but anyways
I created another button with similar code I have seen around.
###################house 1#######
self.house1 = QPushButton(self.centralwidget)
#self.house1 = QtWidgets.QPushButton(self.centralwidget)
self.house1.setGeometry(QtCore.QRect(61, 21, 32, 19))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house1.sizePolicy().hasHeightForWidth())
self.house1.setSizePolicy(sizePolicy)
self.house1.setStyleSheet("#House1 {\n"
"border-image: url(:/img/Crystal_Clear_app_kfm_home.png);\n"
"}\n"
"#House:Pressed {\n"
" border-image: url(:/img/Search_in_home.png);\n"
"}")
self.house1.setText("")
self.house1.setObjectName("house1")
####################end #############
The problem is caused by not using the names correctly, QStyleSheet uses the objectName property, in your case the QPushButton self.house1:
self.house1.setObjectName("house1")
Before writing that line the button has no objectName (actually its objectName is "") so it is not appropriate to place the QStyleSheet by the objectName.
What you should do is place an objectName and then you can just assign the filtered QStyleSheet by its name.
self.house1 = QtWidgets.QPushButton(self.centralwidget)
self.house1.setObjectName("house1")
self.house1.setStyleSheet("#house1 {\n"
"border-image: url(:/img/Crystal_Clear_app_kfm_home.png);\n"
"}\n"
"#house1:Pressed {\n"
" border-image: url(:/img/Search_in_home.png);\n"
"}")
This attribute is case-sensitive so you must place it exactly the same as setObjectName().
For more information you should read the following:
http://doc.qt.io/qt-5/stylesheet-syntax.html
http://doc.qt.io/qt-5/stylesheet-reference.html

PyQt5 GUI runs with no errors but window doesn't appear

The problem is that when I run the PyQt5 GUI after adding resource file and adding PushButtons with border-images on them, mainwindow does not launch and no errors either.
I converted the main window UI to Python with following command:
pyuic5 mainWindow.iu -o mainWindow.py
So this is the mainWindow in python.
from PyQt5 import QtCore, QtGui, QtWidgets
import resources_rc
#import sys
#import random
#import matplotlib
#matplotlib.use("Qt5Agg")
#from PyQt5 import QtCore
#from PyQt5.QtWidgets import QApplication, QMainWindow, QMenu, QVBoxLayout, QSizePolicy, QMessageBox, QWidget
#from numpy import arange, sin, pi
#from matplotlib.backends.backend_qt5agg import FigureCanvasQTAgg as FigureCanvas
#from matplotlib.figure import Figure
#from matplotlib import pyplot as plt
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
MainWindow.setObjectName("MainWindow")
MainWindow.resize(1108, 672)
MainWindow.setAutoFillBackground(False)
MainWindow.setStyleSheet("background-color: rgb(211, 211, 211);")
MainWindow.setIconSize(QtCore.QSize(40, 40))
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
self.verticalScrollBar = QtWidgets.QScrollBar(self.centralwidget)
self.verticalScrollBar.setGeometry(QtCore.QRect(1050, 0, 21, 611))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.MinimumExpanding)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.verticalScrollBar.sizePolicy().hasHeightForWidth())
self.verticalScrollBar.setSizePolicy(sizePolicy)
self.verticalScrollBar.setOrientation(QtCore.Qt.Vertical)
self.verticalScrollBar.setObjectName("verticalScrollBar")
self.horizontalScrollBar = QtWidgets.QScrollBar(self.centralwidget)
self.horizontalScrollBar.setGeometry(QtCore.QRect(0, 610, 1051, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.MinimumExpanding, QtWidgets.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.horizontalScrollBar.sizePolicy().hasHeightForWidth())
self.horizontalScrollBar.setSizePolicy(sizePolicy)
self.horizontalScrollBar.setOrientation(QtCore.Qt.Horizontal)
self.horizontalScrollBar.setObjectName("horizontalScrollBar")
self.label = QtWidgets.QLabel(self.centralwidget)
self.label.setGeometry(QtCore.QRect(900, -30, 151, 141))
self.label.setStyleSheet("border-image: url(:/img/NM_State_University_logo.png);")
self.label.setText("")
self.label.setObjectName("label")
self.house1 = QtWidgets.QPushButton(self.centralwidget)
self.house1.setGeometry(QtCore.QRect(31, 31, 32, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house1.sizePolicy().hasHeightForWidth())
self.house1.setSizePolicy(sizePolicy)
self.house1.setAutoFillBackground(False)
self.house1.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house1.setText("")
self.house1.setObjectName("house1")
self.house2 = QtWidgets.QPushButton(self.centralwidget)
self.house2.setGeometry(QtCore.QRect(258, 31, 32, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house2.sizePolicy().hasHeightForWidth())
self.house2.setSizePolicy(sizePolicy)
self.house2.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house2.setText("")
self.house2.setObjectName("house2")
self.house3 = QtWidgets.QPushButton(self.centralwidget)
self.house3.setGeometry(QtCore.QRect(484, 31, 32, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house3.sizePolicy().hasHeightForWidth())
self.house3.setSizePolicy(sizePolicy)
self.house3.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house3.setText("")
self.house3.setObjectName("house3")
self.house4 = QtWidgets.QPushButton(self.centralwidget)
self.house4.setGeometry(QtCore.QRect(711, 31, 32, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house4.sizePolicy().hasHeightForWidth())
self.house4.setSizePolicy(sizePolicy)
self.house4.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house4.setText("")
self.house4.setIconSize(QtCore.QSize(40, 40))
self.house4.setObjectName("house4")
self.house6 = QtWidgets.QPushButton(self.centralwidget)
self.house6.setGeometry(QtCore.QRect(258, 200, 32, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house6.sizePolicy().hasHeightForWidth())
self.house6.setSizePolicy(sizePolicy)
self.house6.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house6.setText("")
self.house6.setObjectName("house6")
self.house5 = QtWidgets.QPushButton(self.centralwidget)
self.house5.setGeometry(QtCore.QRect(31, 200, 32, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house5.sizePolicy().hasHeightForWidth())
self.house5.setSizePolicy(sizePolicy)
self.house5.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house5.setText("")
self.house5.setObjectName("house5")
self.house9 = QtWidgets.QPushButton(self.centralwidget)
self.house9.setGeometry(QtCore.QRect(31, 368, 32, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house9.sizePolicy().hasHeightForWidth())
self.house9.setSizePolicy(sizePolicy)
self.house9.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house9.setText("")
self.house9.setObjectName("house9")
self.house7 = QtWidgets.QPushButton(self.centralwidget)
self.house7.setGeometry(QtCore.QRect(484, 200, 32, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house7.sizePolicy().hasHeightForWidth())
self.house7.setSizePolicy(sizePolicy)
self.house7.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house7.setText("")
self.house7.setObjectName("house7")
self.house8 = QtWidgets.QPushButton(self.centralwidget)
self.house8.setGeometry(QtCore.QRect(711, 200, 32, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house8.sizePolicy().hasHeightForWidth())
self.house8.setSizePolicy(sizePolicy)
self.house8.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house8.setText("")
self.house8.setIconSize(QtCore.QSize(70, 20))
self.house8.setAutoDefault(True)
self.house8.setObjectName("house8")
self.house11 = QtWidgets.QPushButton(self.centralwidget)
self.house11.setGeometry(QtCore.QRect(484, 368, 32, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house11.sizePolicy().hasHeightForWidth())
self.house11.setSizePolicy(sizePolicy)
self.house11.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house11.setText("")
self.house11.setObjectName("house11")
self.house10 = QtWidgets.QPushButton(self.centralwidget)
self.house10.setGeometry(QtCore.QRect(258, 368, 32, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house10.sizePolicy().hasHeightForWidth())
self.house10.setSizePolicy(sizePolicy)
self.house10.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house10.setText("")
self.house10.setObjectName("house10")
self.house12 = QtWidgets.QPushButton(self.centralwidget)
self.house12.setGeometry(QtCore.QRect(711, 368, 32, 16))
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Preferred, QtWidgets.QSizePolicy.Preferred)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.house12.sizePolicy().hasHeightForWidth())
self.house12.setSizePolicy(sizePolicy)
self.house12.setStyleSheet("border-image: url(:/img/Crystal_Clear_app_kfm_home.png);")
self.house12.setText("")
self.house12.setObjectName("house12")
#####################################Power Plot House 1
self.PowPlotHouse1 = QtWidgets.QWidget(self.centralwidget)
self.PowPlotHouse1.setGeometry(QtCore.QRect(70, 30, 171, 121))
self.PowPlotHouse1.setObjectName("PowPlotHouse1")
#####################END of widge
MainWindow.setCentralWidget(self.centralwidget)
self.menubar = QtWidgets.QMenuBar(MainWindow)
self.menubar.setGeometry(QtCore.QRect(0, 0, 1108, 21))
self.menubar.setObjectName("menubar")
self.menuFile = QtWidgets.QMenu(self.menubar)
self.menuFile.setObjectName("menuFile")
self.menuEdit = QtWidgets.QMenu(self.menubar)
self.menuEdit.setObjectName("menuEdit")
self.menuOptions = QtWidgets.QMenu(self.menubar)
self.menuOptions.setObjectName("menuOptions")
self.menuAdmin = QtWidgets.QMenu(self.menubar)
self.menuAdmin.setObjectName("menuAdmin")
MainWindow.setMenuBar(self.menubar)
self.statusbar = QtWidgets.QStatusBar(MainWindow)
self.statusbar.setObjectName("statusbar")
MainWindow.setStatusBar(self.statusbar)
self.actionSave = QtWidgets.QAction(MainWindow)
self.actionSave.setObjectName("actionSave")
self.actionSave_As = QtWidgets.QAction(MainWindow)
self.actionSave_As.setObjectName("actionSave_As")
self.menuFile.addAction(self.actionSave)
self.menuFile.addAction(self.actionSave_As)
self.menubar.addAction(self.menuFile.menuAction())
self.menubar.addAction(self.menuEdit.menuAction())
self.menubar.addAction(self.menuOptions.menuAction())
self.menubar.addAction(self.menuAdmin.menuAction())
self.retranslateUi(MainWindow)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "MainWindow"))
self.menuFile.setTitle(_translate("MainWindow", "File"))
self.menuEdit.setTitle(_translate("MainWindow", "Edit"))
self.menuOptions.setTitle(_translate("MainWindow", "Options"))
self.menuAdmin.setTitle(_translate("MainWindow", "Admin"))
self.actionSave.setText(_translate("MainWindow", "Save"))
self.actionSave_As.setText(_translate("MainWindow", "Save As"))
import resources_rcenter
I converted my resources file the following way:
pyrcc5 resources.qrc -o resources_rc.py
And my resources file contents
<RCC>
<qresource prefix="newPrefix">
<file>img/Crystal_Clear_app_kfm_home.png</file>
<file>img/Gohomenew.png</file>
<file>img/NM_State_University_logo.png</file>
<file>img/NMlogo_1colorstate_black.png</file>
<file>img/NMSU.png</file>
<file>img/Search_in_home.png</file>
</qresource>
</RCC>
This is the result when trying to run it.
I think about writing an exception to see if it catches anything.
The problem is that the path you use is incorrect, this is caused by the prefix that you do not add.
For example you must change:
self.label.setStyleSheet("border-image: url(:/img/NM_State_University_logo.png);")
to:
self.label.setStyleSheet("border-image: url(:/newPrefix/img/NM_State_University_logo.png);")
But the above can be tedious, a better way is to change the prefix to "/", in that case it should look like this:
<RCC>
<qresource prefix="/">
<file>img/Crystal_Clear_app_kfm_home.png</file>
<file>img/Gohomenew.png</file>
<file>img/NM_State_University_logo.png</file>
<file>img/NMlogo_1colorstate_black.png</file>
<file>img/NMSU.png</file>
<file>img/Search_in_home.png</file>
</qresource>
</RCC>
And then you recompilas with pyrcc5 resources.qrc -o resources_rc.py.
Another problem is that not for an application to be launched in pyqt you must create the application, for this I recommend adding the following to your file mainWindow.py:
if __name__ == "__main__":
app = QtWidgets.QApplication(sys.argv)
w = QtWidgets.QMainWindow()
ui = Ui_MainWindow()
ui.setupUi(w)
w.show()
sys.exit(app.exec_())
Correct the mistype resources_rc and don't forget to create main.py file to call MainWindow.py.
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
from MainWindow import *
import sys
class Main(QMainWindow):
def __init__(self):
super().__init__()
self.ui = Ui_MainWindow()
self.ui.setupUi(self)
self.show()
def main():
app = QApplication(sys.argv)
instance = Main()
sys.exit(app.exec_())
if __name__ == "__main__":
main()
Then run main.py

Issue with scrollarea in pyqt?

This is the file I generated using qt-designer.
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
_fromUtf8 = lambda s: s
class Ui_Dialog(object):
def setupUi(self, Dialog):
Dialog.setObjectName(_fromUtf8("Dialog"))
Dialog.resize(1024, 600)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(Dialog.sizePolicy().hasHeightForWidth())
Dialog.setSizePolicy(sizePolicy)
Dialog.setWindowTitle(QtGui.QApplication.translate("Dialog", "Dialog", None, QtGui.QApplication.UnicodeUTF8))
self.gridLayout = QtGui.QGridLayout(Dialog)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.verticalLayout = QtGui.QVBoxLayout()
self.verticalLayout.setObjectName(_fromUtf8("verticalLayout"))
self.graphicsView = QtGui.QGraphicsView(Dialog)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Fixed)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.graphicsView.sizePolicy().hasHeightForWidth())
self.graphicsView.setSizePolicy(sizePolicy)
self.graphicsView.setVerticalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.graphicsView.setHorizontalScrollBarPolicy(QtCore.Qt.ScrollBarAlwaysOff)
self.graphicsView.setObjectName(_fromUtf8("graphicsView"))
self.verticalLayout.addWidget(self.graphicsView)
self.gridLayout.addLayout(self.verticalLayout, 0, 0, 1, 4)
self.verticalLayout_2 = QtGui.QVBoxLayout()
self.verticalLayout_2.setObjectName(_fromUtf8("verticalLayout_2"))
self.pushButton = QtGui.QPushButton(Dialog)
self.pushButton.setText(QtGui.QApplication.translate("Dialog", "Add", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton.setObjectName(_fromUtf8("pushButton"))
self.verticalLayout_2.addWidget(self.pushButton)
self.gridLayout.addLayout(self.verticalLayout_2, 1, 0, 1, 1)
self.verticalLayout_4 = QtGui.QVBoxLayout()
self.verticalLayout_4.setObjectName(_fromUtf8("verticalLayout_4"))
self.pushButton_2 = QtGui.QPushButton(Dialog)
self.pushButton_2.setText(QtGui.QApplication.translate("Dialog", "Delete", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_2.setObjectName(_fromUtf8("pushButton_2"))
self.verticalLayout_4.addWidget(self.pushButton_2)
self.gridLayout.addLayout(self.verticalLayout_4, 1, 1, 1, 1)
self.verticalLayout_5 = QtGui.QVBoxLayout()
self.verticalLayout_5.setObjectName(_fromUtf8("verticalLayout_5"))
self.pushButton_3 = QtGui.QPushButton(Dialog)
self.pushButton_3.setText(QtGui.QApplication.translate("Dialog", "Edit", None, QtGui.QApplication.UnicodeUTF8))
self.pushButton_3.setObjectName(_fromUtf8("pushButton_3"))
self.verticalLayout_5.addWidget(self.pushButton_3)
self.gridLayout.addLayout(self.verticalLayout_5, 1, 2, 1, 1)
self.verticalLayout_3 = QtGui.QVBoxLayout()
self.verticalLayout_3.setObjectName(_fromUtf8("verticalLayout_3"))
self.label = QtGui.QLabel(Dialog)
self.label.setText(QtGui.QApplication.translate("Dialog", "Connected", None, QtGui.QApplication.UnicodeUTF8))
self.label.setObjectName(_fromUtf8("label"))
self.verticalLayout_3.addWidget(self.label)
self.gridLayout.addLayout(self.verticalLayout_3, 1, 3, 1, 1)
self.horizontalLayout = QtGui.QHBoxLayout()
self.horizontalLayout.setObjectName(_fromUtf8("horizontalLayout"))
self.tableWidget = QtGui.QTableWidget(Dialog)
self.tableWidget.setObjectName(_fromUtf8("tableWidget"))
self.tableWidget.setColumnCount(0)
self.tableWidget.setRowCount(0)
self.horizontalLayout.addWidget(self.tableWidget)
self.gridLayout.addLayout(self.horizontalLayout, 2, 0, 1, 3)
self.horizontalLayout_2 = QtGui.QHBoxLayout()
self.horizontalLayout_2.setObjectName(_fromUtf8("horizontalLayout_2"))
self.tabWidget = QtGui.QTabWidget(Dialog)
self.tabWidget.setObjectName(_fromUtf8("tabWidget"))
self.tab = QtGui.QWidget()
self.tab.setObjectName(_fromUtf8("tab"))
self.verticalLayout_6 = QtGui.QVBoxLayout(self.tab)
self.verticalLayout_6.setObjectName(_fromUtf8("verticalLayout_6"))
self.scrollArea = QtGui.QScrollArea(self.tab)
self.scrollArea.setWidgetResizable(True)
self.scrollArea.setObjectName(_fromUtf8("scrollArea"))
self.scrollAreaWidgetContents = QtGui.QWidget(self.scrollArea)
self.scrollAreaWidgetContents.setGeometry(QtCore.QRect(0, 0, 701, 292))
self.scrollAreaWidgetContents.setObjectName(_fromUtf8("scrollAreaWidgetContents"))
self.verticalLayout_7 = QtGui.QVBoxLayout(self.scrollAreaWidgetContents)
self.verticalLayout_7.setObjectName(_fromUtf8("verticalLayout_7"))
self.dockWidget = QtGui.QDockWidget(self.scrollAreaWidgetContents)
self.dockWidget.setObjectName(_fromUtf8("dockWidget"))
self.dockWidgetContents = QtGui.QWidget()
self.dockWidgetContents.setObjectName(_fromUtf8("dockWidgetContents"))
self.verticalLayout_8 = QtGui.QVBoxLayout(self.dockWidgetContents)
self.verticalLayout_8.setObjectName(_fromUtf8("verticalLayout_8"))
self.plainTextEdit = QtGui.QPlainTextEdit(self.dockWidgetContents)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Ignored)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.plainTextEdit.sizePolicy().hasHeightForWidth())
self.plainTextEdit.setSizePolicy(sizePolicy)
self.plainTextEdit.setObjectName(_fromUtf8("plainTextEdit"))
self.verticalLayout_8.addWidget(self.plainTextEdit)
self.dockWidget.setWidget(self.dockWidgetContents)
self.verticalLayout_7.addWidget(self.dockWidget)
self.dockWidget_2 = QtGui.QDockWidget(self.scrollAreaWidgetContents)
self.dockWidget_2.setObjectName(_fromUtf8("dockWidget_2"))
self.dockWidgetContents_2 = QtGui.QWidget()
self.dockWidgetContents_2.setObjectName(_fromUtf8("dockWidgetContents_2"))
self.verticalLayout_9 = QtGui.QVBoxLayout(self.dockWidgetContents_2)
self.verticalLayout_9.setObjectName(_fromUtf8("verticalLayout_9"))
self.plainTextEdit_2 = QtGui.QPlainTextEdit(self.dockWidgetContents_2)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Ignored)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.plainTextEdit_2.sizePolicy().hasHeightForWidth())
self.plainTextEdit_2.setSizePolicy(sizePolicy)
self.plainTextEdit_2.setObjectName(_fromUtf8("plainTextEdit_2"))
self.verticalLayout_9.addWidget(self.plainTextEdit_2)
self.dockWidget_2.setWidget(self.dockWidgetContents_2)
self.verticalLayout_7.addWidget(self.dockWidget_2)
self.dockWidget_3 = QtGui.QDockWidget(self.scrollAreaWidgetContents)
self.dockWidget_3.setObjectName(_fromUtf8("dockWidget_3"))
self.dockWidgetContents_3 = QtGui.QWidget()
self.dockWidgetContents_3.setObjectName(_fromUtf8("dockWidgetContents_3"))
self.verticalLayout_10 = QtGui.QVBoxLayout(self.dockWidgetContents_3)
self.verticalLayout_10.setObjectName(_fromUtf8("verticalLayout_10"))
self.plainTextEdit_3 = QtGui.QPlainTextEdit(self.dockWidgetContents_3)
sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Ignored, QtGui.QSizePolicy.Ignored)
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.plainTextEdit_3.sizePolicy().hasHeightForWidth())
self.plainTextEdit_3.setSizePolicy(sizePolicy)
self.plainTextEdit_3.setObjectName(_fromUtf8("plainTextEdit_3"))
self.verticalLayout_10.addWidget(self.plainTextEdit_3)
self.dockWidget_3.setWidget(self.dockWidgetContents_3)
self.verticalLayout_7.addWidget(self.dockWidget_3)
self.scrollArea.setWidget(self.scrollAreaWidgetContents)
self.verticalLayout_6.addWidget(self.scrollArea)
self.tabWidget.addTab(self.tab, _fromUtf8(""))
self.tab_2 = QtGui.QWidget()
self.tab_2.setObjectName(_fromUtf8("tab_2"))
self.tabWidget.addTab(self.tab_2, _fromUtf8(""))
self.horizontalLayout_2.addWidget(self.tabWidget)
self.gridLayout.addLayout(self.horizontalLayout_2, 2, 3, 1, 1)
self.retranslateUi(Dialog)
QtCore.QMetaObject.connectSlotsByName(Dialog)
def retranslateUi(self, Dialog):
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab), QtGui.QApplication.translate("Dialog", "Tab 1", None, QtGui.QApplication.UnicodeUTF8))
self.tabWidget.setTabText(self.tabWidget.indexOf(self.tab_2), QtGui.QApplication.translate("Dialog", "Tab 2", None, QtGui.QApplication.UnicodeUTF8))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Dialog = QtGui.QDialog()
ui = Ui_Dialog()
ui.setupUi(Dialog)
Dialog.show()
sys.exit(app.exec_())
The output is in the screenshot: The problem is that the Tab1 is not showing any scrollbar even I set the layout under scrollArea. The region where I am expecting a scrollbar is shown by a red rectangle.
I remember this similar question :-) How to associate a horizontal scrollbar to multiple groupbox.?
The reason you are still not getting proper scrollbars is because your widgets inside the scrollarea don't have a minimum height and are being allowed to shrink far enough down that they would never force the scrollarea to display its scrollbars.
In code, you can fix this by:
self.dockWidgetContents.setMinimumHeight(100)
Althought, you shouldn't be making any direct edits to this file being generated from Qt Designer. What you should do is go into QtDesigner, select the widgets, and at the top of their property list, set a minimum height for them.

Categories

Resources