我想调整qtabwidget的大小,当选择不同的标签时,我正在使用pyqt工具进行设计。所以我想要调整大小标签窗口。
def setupUi(self, AccountsUI):
AccountsUI.setObjectName("AccountsUI")
AccountsUI.setWindowModality(QtCore.Qt.NonModal)
AccountsUI.resize(600, 847)
self.Accounts = QtWidgets.QTabWidget(AccountsUI)
self.Accounts.setGeometry(QtCore.QRect(30, 20, 501, 821))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.Accounts.setFont(font)
self.Accounts.setStyleSheet()
self.Accounts.setTabPosition(QtWidgets.QTabWidget.North)
self.Accounts.setTabShape(QtWidgets.QTabWidget.Rounded)
self.Accounts.setObjectName("Accounts")
self.Account = QtWidgets.QWidget()
self.Account.setObjectName("Account")
self.accountname_textbox = QtWidgets.QLineEdit(self.Account)
self.accountname_textbox.setGeometry(QtCore.QRect(120, 20, 231, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.accountname_textbox.setFont(font)
self.accountname_textbox.setObjectName("accountname_textbox")
self.accountname_textbox.setText('Account1')
self.accountname_label = QtWidgets.QLabel(self.Account)
self.accountname_label.setGeometry(QtCore.QRect(10, 20, 101, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(12)
self.accountname_label.setFont(font)
self.accountname_label.setObjectName("accountname_label")
self.protocol_label = QtWidgets.QLabel(self.Account)
self.protocol_label.setGeometry(QtCore.QRect(20, 70, 91, 21))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(12)
self.protocol_label.setFont(font)
self.protocol_label.setObjectName("protocol_label")
self.protocol_textbox = QtWidgets.QLineEdit(self.Account)
self.protocol_textbox.setGeometry(QtCore.QRect(120, 70, 231, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(12)
self.protocol_textbox.setFont(font)
self.protocol_textbox.setObjectName("protocol_textbox")
self.protocol_textbox.setText('SIP')
self.account_frame = QtWidgets.QFrame(self.Account)
self.account_frame.setGeometry(QtCore.QRect(10, 160, 471, 71))
self.account_frame.setStyleSheet()
self.account_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.account_frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.account_frame.setObjectName("account_frame")
self.call_checkbox = QtWidgets.QCheckBox(self.account_frame)
self.call_checkbox.setGeometry(QtCore.QRect(10, 10, 91, 17))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.call_checkbox.setFont(font)
self.call_checkbox.setObjectName("call_checkbox")
self.call_checkbox.setChecked(True)
self.impresence_checkbox = QtWidgets.QCheckBox(self.account_frame)
self.impresence_checkbox.setGeometry(QtCore.QRect(10, 40, 101, 17))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.impresence_checkbox.setFont(font)
self.impresence_checkbox.setObjectName("impresence_checkbox")
self.impresence_checkbox.setChecked(True)
self.heading_label = QtWidgets.QLabel(self.Account)
self.heading_label.setGeometry(QtCore.QRect(20, 130, 151, 21))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(12)
font.setUnderline(False)
self.heading_label.setFont(font)
self.heading_label.setObjectName("heading_label")
self.userdetails_frame = QtWidgets.QFrame(self.Account)
self.userdetails_frame.setGeometry(QtCore.QRect(10, 290, 471, 221))
self.userdetails_frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
self.userdetails_frame.setFrameShadow(QtWidgets.QFrame.Raised)
self.userdetails_frame.setObjectName("userdetails_frame")
self.userid_textbox = QtWidgets.QLineEdit(self.userdetails_frame)
self.userid_textbox.setGeometry(QtCore.QRect(140, 20, 221, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.userid_textbox.setFont(font)
self.userid_textbox.setObjectName("userid_textbox")
self.domain_textbox = QtWidgets.QLineEdit(self.userdetails_frame)
self.domain_textbox.setGeometry(QtCore.QRect(140, 60, 221, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.domain_textbox.setFont(font)
self.domain_textbox.setObjectName("domain_textbox")
self.password_textbox = QtWidgets.QLineEdit(self.userdetails_frame)
self.password_textbox.setEchoMode(QtWidgets.QLineEdit.Password)
self.password_textbox.setGeometry(QtCore.QRect(140, 100, 221, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.password_textbox.setFont(font)
self.password_textbox.setObjectName("password_textbox")
self.displayname_textbox = QtWidgets.QLineEdit(self.userdetails_frame)
self.displayname_textbox.setGeometry(QtCore.QRect(140, 140, 221, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.displayname_textbox.setFont(font)
self.displayname_textbox.setObjectName("displayname_textbox")
self.authname_textbox = QtWidgets.QLineEdit(self.userdetails_frame)
self.authname_textbox.setGeometry(QtCore.QRect(140, 180, 221, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.authname_textbox.setFont(font)
self.authname_textbox.setObjectName("authname_textbox")
self.userid_label = QtWidgets.QLabel(self.userdetails_frame)
self.userid_label.setGeometry(QtCore.QRect(80, 20, 61, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.userid_label.setFont(font)
self.userid_label.setObjectName("userid_label")
self.domain_label = QtWidgets.QLabel(self.userdetails_frame)
self.domain_label.setGeometry(QtCore.QRect(80, 60, 61, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.domain_label.setFont(font)
self.domain_label.setObjectName("domain_label")
self.password_label = QtWidgets.QLabel(self.userdetails_frame)
self.password_label.setGeometry(QtCore.QRect(70, 100, 71, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.password_label.setFont(font)
self.password_label.setObjectName("password_label")
self.displayname_label = QtWidgets.QLabel(self.userdetails_frame)
self.displayname_label.setGeometry(QtCore.QRect(50, 140, 91, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.displayname_label.setFont(font)
self.displayname_label.setObjectName("displayname_label")
self.authname_label = QtWidgets.QLabel(self.userdetails_frame)
self.authname_label.setGeometry(QtCore.QRect(10, 180, 131, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.authname_label.setFont(font)
self.authname_label.setObjectName("authname_label")
self.userdetails_heading = QtWidgets.QLabel(self.Account)
self.userdetails_heading.setGeometry(QtCore.QRect(20, 250, 121, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(12)
self.userdetails_heading.setFont(font)
self.userdetails_heading.setObjectName("userdetails_heading")
self.domainproxy_heading = QtWidgets.QLabel(self.Account)
self.domainproxy_heading.setGeometry(QtCore.QRect(20, 530, 101, 21))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(12)
self.domainproxy_heading.setFont(font)
self.domainproxy_heading.setObjectName("domainproxy_heading")
self.domainproxy_frame = QtWidgets.QFrame(self.Account)
self.domainproxy_frame.setGeometry(QtCore.QRect(10, 560, 471, 121))
self.domainproxy_frame.setStyleSheet()
self.registerdomain_checkbox = QtWidgets.QCheckBox(self.domainproxy_frame)
self.registerdomain_checkbox.setGeometry(QtCore.QRect(9, 10, 261, 20))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.registerdomain_checkbox.setFont(font)
self.registerdomain_checkbox.setObjectName("registerdomain_checkbox")
self.sendoutbound_label = QtWidgets.QLabel(self.domainproxy_frame)
self.sendoutbound_label.setGeometry(QtCore.QRect(10, 40, 121, 16))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.sendoutbound_label.setFont(font)
self.sendoutbound_label.setObjectName("sendoutbound_label")
self.domain_radiobtn = QtWidgets.QRadioButton(self.domainproxy_frame)
self.domain_radiobtn.setGeometry(QtCore.QRect(10, 60, 82, 17))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(10)
self.domain_radiobtn.setFont(font)
self.domain_radiobtn.setObjectName("domain_radiobtn")
self.proxyaddress_radiobtn = QtWidgets.QRadioButton(self.domainproxy_frame)
self.proxyaddress_radiobtn.setGeometry(QtCore.QRect(10, 90, 101, 17))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(10)
self.proxyaddress_radiobtn.setFont(font)
self.proxyaddress_radiobtn.setObjectName("proxyaddress_radiobtn")
self.proxyaddress_textbox = QtWidgets.QLineEdit(self.domainproxy_frame)
self.proxyaddress_textbox.setGeometry(QtCore.QRect(140, 80, 211, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.proxyaddress_textbox.setFont(font)
self.proxyaddress_textbox.setObjectName("proxyaddress_textbox")
self.dialplan_label = QtWidgets.QLabel(self.Account)
self.dialplan_label.setGeometry(QtCore.QRect(20, 700, 71, 21))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.dialplan_label.setFont(font)
self.dialplan_label.setObjectName("dialplan_label")
self.dialplan_textbox = QtWidgets.QLineEdit(self.Account)
self.dialplan_textbox.setGeometry(QtCore.QRect(90, 700, 281, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.dialplan_textbox.setFont(font)
self.dialplan_textbox.setObjectName("dialplan_textbox")
self.accountok_btn = QtWidgets.QPushButton(self.Account)
self.accountok_btn.setGeometry(QtCore.QRect(330, 750, 75, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(12)
self.accountok_btn.setFont(font)
self.accountok_btn.setObjectName("accountok_btn")
self.accountok_btn.clicked.connect(self.insertdata)
self.accountcancel_btn = QtWidgets.QPushButton(self.Account)
self.accountcancel_btn.setGeometry(QtCore.QRect(410, 750, 75, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(12)
self.accountcancel_btn.setFont(font)
self.accountcancel_btn.setObjectName("accountcancel_btn")
self.accountcancel_btn.clicked.connect(self.cancelwindow)
self.Accounts.addTab(self.Account, "")
self.Voicemail = QtWidgets.QWidget()
self.Voicemail.setObjectName("Voicemail")
self.checkvoicemail_checkbox = QtWidgets.QCheckBox(self.Voicemail)
self.checkvoicemail_checkbox.setGeometry(QtCore.QRect(20, 30, 151, 17))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.checkvoicemail_checkbox.setFont(font)
self.checkvoicemail_checkbox.setObjectName("checkvoicemail_checkbox")
self.checkvoicemail_checkbox.setChecked(True)
self.numbertodial_label = QtWidgets.QLabel(self.Voicemail)
self.numbertodial_label.setGeometry(QtCore.QRect(40, 80, 241, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.numbertodial_label.setFont(font)
self.numbertodial_label.setObjectName("numbertodial_label")
self.dialvoicemail_textbox = QtWidgets.QLineEdit(self.Voicemail)
self.dialvoicemail_textbox.setGeometry(QtCore.QRect(290, 80, 151, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.dialvoicemail_textbox.setFont(font)
self.dialvoicemail_textbox.setObjectName("dialvoicemail_textbox")
self.callsvoicemail_textbox = QtWidgets.QLineEdit(self.Voicemail)
self.callsvoicemail_textbox.setGeometry(QtCore.QRect(290, 130, 151, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.callsvoicemail_textbox.setFont(font)
self.callsvoicemail_textbox.setObjectName("callsvoicemail_textbox")
self.numbertosend_label = QtWidgets.QLabel(self.Voicemail)
self.numbertosend_label.setGeometry(QtCore.QRect(40, 130, 241, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.numbertosend_label.setFont(font)
self.numbertosend_label.setObjectName("numbertosend_label")
self.unansweredcall_checkbox = QtWidgets.QCheckBox(self.Voicemail)
self.unansweredcall_checkbox.setGeometry(QtCore.QRect(40, 190, 281, 17))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.unansweredcall_checkbox.setFont(font)
self.unansweredcall_checkbox.setObjectName("unansweredcall_checkbox")
self.unansweredcall_textbox = QtWidgets.QLineEdit(self.Voicemail)
self.unansweredcall_textbox.setGeometry(QtCore.QRect(330, 180, 51, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.unansweredcall_textbox.setFont(font)
self.unansweredcall_textbox.setObjectName("unansweredcall_textbox")
self.unansweredcall_textbox.setText('0')
self.seconds_label = QtWidgets.QLabel(self.Voicemail)
self.seconds_label.setGeometry(QtCore.QRect(390, 190, 61, 16))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(11)
self.seconds_label.setFont(font)
self.seconds_label.setObjectName("seconds_label")
self.voicemailcancel_btn = QtWidgets.QPushButton(self.Voicemail)
self.voicemailcancel_btn.setGeometry(QtCore.QRect(410, 230, 75, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(12)
self.voicemailcancel_btn.setFont(font)
self.voicemailcancel_btn.setObjectName("voicemailcancel_btn")
self.voicemailcancel_btn.clicked.connect(self.cancelwindow)
self.voicemailok_btn = QtWidgets.QPushButton(self.Voicemail)
self.voicemailok_btn.setGeometry(QtCore.QRect(330, 230, 75, 31))
font = QtGui.QFont()
font.setFamily("Sylfaen")
font.setPointSize(12)
self.voicemailok_btn.setFont(font)
self.voicemailok_btn.setObjectName("voicemailok_btn")
self.voicemailok_btn.clicked.connect(self.voicemaildata)
所以我想解决这个问题,在这个代码中创建了两个标签Account,Voicemail。帐号页面大小(501,847),相同大小的语音邮件页面,所以我想要解决这个问题。当我选择语音邮件选项卡时,页面大小应根据该页面中的内容调整大小。
答案 0 :(得分:0)
您可以使用更改选项卡时发出的QTabWidget.currentChanged()信号,然后根据选项卡调整窗口大小,例如:
self.yourTabWidget.currentChanged.connect(self.tab_changed)
def tab_changed(self):
if self.yourTabWidget.currentIndex == 0:
self.setGeometry(x, x, x, x) # size for first tab
elif self.yourTabWidget.currentIndex == 1:
self.setGeometry(x, x, x, x) # size for second tab
在第一个标签测量开始时使用self.setGeometry()
如果您也不想更改位置,可以使用self.resize()
代替self.setGeometry()