Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Event filter for QtabWidget (PySide6)
Forum Updated to NodeBB v4.3 + New Features

Event filter for QtabWidget (PySide6)

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 727 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • E Offline
    E Offline
    electric-dev
    wrote on 14 Nov 2024, 03:07 last edited by
    #1

    Hello good evening ,I am creating an event filter so that when a number entered to a Qspinbox exceeds the number 10,you can not access the tabs of a QtabWidget.

    The problem I have is that if the application is minimized when the value of the QSpinbox exceeds the number 10 the tabs disappear and until this value decreases and I pass the mouse over where the tabs should be, they are not shown.
    This is the code I have so far:

    
    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("Now you see it", 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 hope you can help me

    P 1 Reply Last reply 14 Nov 2024, 04:17
    0
    • E Offline
      E Offline
      electric-dev
      wrote on 16 Nov 2024, 00:28 last edited by
      #3

      Thank you so much ,it works that way ,on the other hand ,i dont limit the values because it is needed that way

      1 Reply Last reply
      0
      • E electric-dev
        14 Nov 2024, 03:07

        Hello good evening ,I am creating an event filter so that when a number entered to a Qspinbox exceeds the number 10,you can not access the tabs of a QtabWidget.

        The problem I have is that if the application is minimized when the value of the QSpinbox exceeds the number 10 the tabs disappear and until this value decreases and I pass the mouse over where the tabs should be, they are not shown.
        This is the code I have so far:

        
        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("Now you see it", 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 hope you can help me

        P Offline
        P Offline
        Pl45m4
        wrote on 14 Nov 2024, 04:17 last edited by Pl45m4
        #2

        @electric-dev

        Hi and welcome to the forum,

        The main problem is, that you block EVERY event that is coming from or going to the tabBar when value > 10...
        so also events, that are required to make the widget/app run and get drawn smoothly.

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

        Actually you don't need an eventFilter at all.
        I think using a signal from your QSpinBox to disable the QTabWidget (or QTabBar) is a better approach.

        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.boton1 = QSpinBox(a)
                self.boton1.setGeometry(20, 20, 130, 30)
                self.boton1.setValue(5)
        
                self.label = QLabel("Now you see it", b)
                self.label.setGeometry(140, 40, 80, 60)
        
                self.boton1.valueChanged.connect(self.handleSpinBoxValue)
        
        
            def handleSpinBoxValue(self, value):
                
                 if value > 10:
                    self.tab.tabBar().setDisabled(True)
                 else:
                    self.tab.tabBar().setDisabled(False)
        
        
        app = QApplication(sys.argv)
        window = MainWindow()
        window.show()
        app.exec()
        

        Works like this:

        TabSpinBox.gif

        I did it in C++, but the Python code above should work.
        (Note: when other people should use your app, you should inform the user somehow that a value greater than 10 disables the other tabs)

        While writing this:
        Why don't you limit the maximum value of your spinBox? So that it's never above 10?!

        self.boton1.setRange(0, 10)
        self.boton1.setValue(5)
        

        Or should higher numbers still be possible?


        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        1 Reply Last reply
        3
        • E Offline
          E Offline
          electric-dev
          wrote on 16 Nov 2024, 00:28 last edited by
          #3

          Thank you so much ,it works that way ,on the other hand ,i dont limit the values because it is needed that way

          1 Reply Last reply
          0
          • E electric-dev has marked this topic as solved on 16 Nov 2024, 00:29

          1/3

          14 Nov 2024, 03:07

          • Login

          • Login or register to search.
          1 out of 3
          • First post
            1/3
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved