Event filter for QtabWidget

Hello good evening ,I am creating an event filter for when a value of a Qspinbox exceeds a value can not access a tab of a QtabWidget.
The problem I have is that if the application is minimized when the value of the QSpinbox exceeds the preset value the tabs disappear and until this value decreases and pass the mouse where the tabs should be these are not displayed.
This is the code i have so far:

import sys

from PySide6.QtWidgets import QApplication, QLabel, QMainWindow,QSpinBox,QHBoxLayout,QMessageBox,QTabWidget,QWidget
from PySide6.QtCore import Qt,QEvent

class MainWindow(QMainWindow):
def init(self):
super().init()

    self.setFixedSize(400,200)

    a=QWidget()
    b=QWidget()

    self.tab=QTabWidget(self)
    
    self.tab.addTab(a,"Hola")
    self.tab.addTab(b,"Saludos")
    self.setCentralWidget(self.tab)

    self.tab.tabBar().installEventFilter(self)
    

    self.botón1=QSpinBox(a)
    self.botón1.setGeometry(20,20,130,30)
    self.botón1.setValue(5)

    self.label=QLabel("Ahora lo ves",b)
    self.label.setGeometry(140,40,80,60)

def eventFilter(self, object, event):
    if object == self.tab.tabBar() and  self.botón1.value()>10:
        
        return True
    else:
      
     return False

app = QApplication(sys.argv)

window = MainWindow()
window.show()

app.exec()

Hello @Damian
I manage run your example.

import sys

from PySide6.QtWidgets import QApplication, QLabel, QMainWindow, QSpinBox, QTabWidget, QWidget


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        self.setFixedSize(400, 200)
        a = QWidget()
        b = QWidget()
        self.tab = QTabWidget(self)
        self.tab.addTab(a, "Hola")
        self.tab.addTab(b, "Saludos")
        self.setCentralWidget(self.tab)
        self.tab.tabBar().installEventFilter(self)
        self.boton1 = QSpinBox(a)
        self.boton1.setGeometry(20, 20, 130, 30)
        self.boton1.setValue(5)

        self.label = QLabel("Ahora lo ves", b)
        self.label.setGeometry(140, 40, 80, 60)


    def eventFilter(self, object, event):
        if object == self.tab.tabBar() and self.boton1.value() > 10:
            return True
        else:
            return False


app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()

I’m not sure how to reproduce your problem. Don’t really understand what you mean.

Hello thank you very much for replying ,to show the problem I have ,I think I better send pictures.

As you can see, the QtabWidget tabs disappear when the app is minimized.

Ok great, I got it… And what you want achieve, what is your goal?

My goal is to prevent the user from being unable to enter the ´´Saludos´´ tab when the numeric value entered in the QSpinBox exceeds 10.

I’m not familiar with eventFilter() at all, but I would do something like:

import sys

from PySide6.QtWidgets import QApplication, QLabel, QMainWindow, QSpinBox, QTabWidget, QWidget


class MainWindow(QMainWindow):
    def __init__(self) -> None:
        super().__init__()
        self.setFixedSize(400, 200)
        a = QWidget()
        b = QWidget()
        self.tab = QTabWidget(self)
        self.tab.addTab(a, "Hola")
        self.tab.addTab(b, "Saludos")
        self.setCentralWidget(self.tab)
        self.boton1 = QSpinBox(a)
        self.boton1.setGeometry(20, 20, 130, 30)
        self.boton1.setValue(5)

        self.label = QLabel("Ahora lo ves", b)
        self.label.setGeometry(140, 40, 80, 60)
        self.boton1.valueChanged.connect(self.spin_value_changed)

    def _get_tab_index(self, text) -> int:
        for i in range(self.tab.count()):
            if self.tab.tabText(i) == text:
                return i
        return -1

    def spin_value_changed(self, value: int) -> None:
        idx = self._get_tab_index('Saludos')
        if value > 10:
            self.tab.setTabEnabled(idx, False)
        else:
            self.tab.setTabEnabled(idx, True)

app = QApplication(sys.argv)
window = MainWindow()
window.show()
app.exec()
1 Like

Thank you so much, it is work fine

1 Like

so please make thread as solved :wink:

Sorry ,I dont see a option for solved or i just write solved in the las commentary?

under a post there is a checkbox:
image