Q:

How to resize Qtabwidget for different different tabs?

I want to resize  qtabwidget,when select differnt tabs,i am using pyqt tool for designing.so i want resize tab window.
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)

So i want to solution for this problem,in this code two tabs are created Account,Voicemail. Account page  size(501,847) that same size is for voicemail page,so i want solution for this problem.when  i select voicemail tab that page size should be resized according to the content in that page.

A:

You can use QTabWidget.currentChanged() signal which emits when the tab is changed and then resize the window based on tab for example:
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

And use self.setGeometry() at start with the first tab measurements
If you don't want to change the position too, you can use self.resize() instead of self.setGeometry()

