Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Disable or hide QLineEdit if one option from the QComboBox is active
Forum Update on Monday, May 27th 2025

Disable or hide QLineEdit if one option from the QComboBox is active

Scheduled Pinned Locked Moved Unsolved Qt for Python
4 Posts 2 Posters 1.1k Views
  • 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.
  • T Offline
    T Offline
    TitoElan
    wrote on last edited by
    #1

    Hi! It is my first day and I am trying to hide one QLineEdit while one option from the QComboBox is selected. I tried many things but without luck. Maybe can I get here some help.
    Here is the code. I just want to hide the QLineEdit self.edit_winkel if the combobox is showing "Kehlnaht".

    Thanks!

    from operator import index
    import sys
    from cmath import pi
    import math
    from tkinter import E
    from PySide6.QtWidgets import (QLineEdit, QPushButton, QApplication,
        QVBoxLayout, QDialog, QFontComboBox, QComboBox,QHBoxLayout,QLabel,QGridLayout,QGroupBox,QTextEdit)
    from matplotlib import widgets
    
    class Form(QDialog):
    
        def __init__(self, parent=None):
            super(Form, self).__init__(parent)
            # Create widgets
            self.edit_dicke = QLineEdit("")
            self.edit_V = QLineEdit("")
            self.edit_laenge = QLineEdit("")
            self.edit_winkel = QLineEdit("")
            self.button = QPushButton("Berechnen")
            self.label_dicke = QLabel("a [mm] = ")
            self.label_Naht = QLabel("Naht ")
            self.label_V = QLabel("V [mm] =  ")
            self.label_laenge = QLabel("L [m] =  ")
            self.label_winkel = QLabel("Winkel [°] =  ")
            self.combobox_Nahtselector = QComboBox()
            self.combobox_Nahtselector.addItem("Kehlnaht")
            self.combobox_Nahtselector.addItem("V-Naht")
            self.combobox_Nahtselector.addItem("HV-Naht")
            self.gb = QTextEdit()
    
            # Create layout and add widgets
            layout = QGridLayout()
            layout.addWidget(self.label_Naht,0,0)
            layout.addWidget(self.combobox_Nahtselector,0,2)
            layout.addWidget(self.label_dicke,1,0)
            layout.addWidget(self.edit_dicke,1,2)
            layout.addWidget(self.label_V,2,0)
            layout.addWidget(self.edit_V,2,2)
            layout.addWidget(self.label_winkel,3,0)
            layout.addWidget(self.edit_winkel,3,2)       
            layout.addWidget(self.label_laenge,4,0)
            layout.addWidget(self.edit_laenge,4,2)
            layout.addWidget(self.button,5,2)
            layout.addWidget(self.gb,6,0,6,3)
    
            
            # Set dialog layout
            self.setLayout(layout)
    
    
            # finding the content of current item in combo box
            content = self.combobox_Nahtselector.currentText()
    
    
            # self.combobox_Nahtselector.currentIndexChanged.connect(self.combobox)
    
        def currentIndexChanged(self):
            if self.combobox_Nahtselector.currentText == "Kehlnaht":
                self.edit_winkel.setEnabled(False)
            else:
                self.edit_winkel.setEnabled(True)
    
    
        
    
    if __name__ == '__main__':
        # Create the Qt Application
        app = QApplication(sys.argv)
        # Create and show the form
        form = Form()
        form.show()
        # Run the main Qt loop
        sys.exit(app.exec())
    
    JonBJ 1 Reply Last reply
    0
    • T TitoElan

      Hi! It is my first day and I am trying to hide one QLineEdit while one option from the QComboBox is selected. I tried many things but without luck. Maybe can I get here some help.
      Here is the code. I just want to hide the QLineEdit self.edit_winkel if the combobox is showing "Kehlnaht".

      Thanks!

      from operator import index
      import sys
      from cmath import pi
      import math
      from tkinter import E
      from PySide6.QtWidgets import (QLineEdit, QPushButton, QApplication,
          QVBoxLayout, QDialog, QFontComboBox, QComboBox,QHBoxLayout,QLabel,QGridLayout,QGroupBox,QTextEdit)
      from matplotlib import widgets
      
      class Form(QDialog):
      
          def __init__(self, parent=None):
              super(Form, self).__init__(parent)
              # Create widgets
              self.edit_dicke = QLineEdit("")
              self.edit_V = QLineEdit("")
              self.edit_laenge = QLineEdit("")
              self.edit_winkel = QLineEdit("")
              self.button = QPushButton("Berechnen")
              self.label_dicke = QLabel("a [mm] = ")
              self.label_Naht = QLabel("Naht ")
              self.label_V = QLabel("V [mm] =  ")
              self.label_laenge = QLabel("L [m] =  ")
              self.label_winkel = QLabel("Winkel [°] =  ")
              self.combobox_Nahtselector = QComboBox()
              self.combobox_Nahtselector.addItem("Kehlnaht")
              self.combobox_Nahtselector.addItem("V-Naht")
              self.combobox_Nahtselector.addItem("HV-Naht")
              self.gb = QTextEdit()
      
              # Create layout and add widgets
              layout = QGridLayout()
              layout.addWidget(self.label_Naht,0,0)
              layout.addWidget(self.combobox_Nahtselector,0,2)
              layout.addWidget(self.label_dicke,1,0)
              layout.addWidget(self.edit_dicke,1,2)
              layout.addWidget(self.label_V,2,0)
              layout.addWidget(self.edit_V,2,2)
              layout.addWidget(self.label_winkel,3,0)
              layout.addWidget(self.edit_winkel,3,2)       
              layout.addWidget(self.label_laenge,4,0)
              layout.addWidget(self.edit_laenge,4,2)
              layout.addWidget(self.button,5,2)
              layout.addWidget(self.gb,6,0,6,3)
      
              
              # Set dialog layout
              self.setLayout(layout)
      
      
              # finding the content of current item in combo box
              content = self.combobox_Nahtselector.currentText()
      
      
              # self.combobox_Nahtselector.currentIndexChanged.connect(self.combobox)
      
          def currentIndexChanged(self):
              if self.combobox_Nahtselector.currentText == "Kehlnaht":
                  self.edit_winkel.setEnabled(False)
              else:
                  self.edit_winkel.setEnabled(True)
      
      
          
      
      if __name__ == '__main__':
          # Create the Qt Application
          app = QApplication(sys.argv)
          # Create and show the form
          form = Form()
          form.show()
          # Run the main Qt loop
          sys.exit(app.exec())
      
      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @TitoElan said in Disable or hide QLineEdit if one option from the QComboBox is active:

          # finding the content of current item in combo box
          content = self.combobox_Nahtselector.currentText()
      
      
          # self.combobox_Nahtselector.currentIndexChanged.connect(self.combobox)
      

      Hello and weclome.

      The uncommented line won't help you, as it only tells you what the value is while you are inside __init__(). The commented line is indeed what you will need: connecting the signal to your slot. But aren't your parameters wrong? Don't you want:

      self.combobox_Nahtselector.currentIndexChanged.connect(self.currentIndexChanged)
      

      You connect the combobox's currentIndexChanged signal to a slot method you write, here Form's currentIndexChanged().

      When that's working, you might rename def currentIndexChanged(self): to def combobox_NahtselectorCurrentIndexChanged(self) because that what it is a slot for and might make it clearer to you what is going on.

      T 1 Reply Last reply
      1
      • JonBJ JonB

        @TitoElan said in Disable or hide QLineEdit if one option from the QComboBox is active:

            # finding the content of current item in combo box
            content = self.combobox_Nahtselector.currentText()
        
        
            # self.combobox_Nahtselector.currentIndexChanged.connect(self.combobox)
        

        Hello and weclome.

        The uncommented line won't help you, as it only tells you what the value is while you are inside __init__(). The commented line is indeed what you will need: connecting the signal to your slot. But aren't your parameters wrong? Don't you want:

        self.combobox_Nahtselector.currentIndexChanged.connect(self.currentIndexChanged)
        

        You connect the combobox's currentIndexChanged signal to a slot method you write, here Form's currentIndexChanged().

        When that's working, you might rename def currentIndexChanged(self): to def combobox_NahtselectorCurrentIndexChanged(self) because that what it is a slot for and might make it clearer to you what is going on.

        T Offline
        T Offline
        TitoElan
        wrote on last edited by
        #3

        @JonB thanks! I'm not sure how, but it works now. I guess I need to read some documentation about the signals and slots. :D

        JonBJ 1 Reply Last reply
        0
        • T TitoElan

          @JonB thanks! I'm not sure how, but it works now. I guess I need to read some documentation about the signals and slots. :D

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by JonB
          #4

          @TitoElan said in Disable or hide QLineEdit if one option from the QComboBox is active:

          I guess I need to read some documentation about the signals and slots. :D

          Understatement! You won't get anywhere in Qt with understanding signal & slots. Read through https://doc.qt.io/qt-5/signalsandslots.html and https://wiki.qt.io/Qt_for_Python_Signals_and_Slots. For Python there are slight differences (syntax) between PyQt vs PySide, so decide which you are using.

          1 Reply Last reply
          1

          • Login

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