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. How to disable Second QComboBox by clicking on the first QComboBox?

How to disable Second QComboBox by clicking on the first QComboBox?

Scheduled Pinned Locked Moved Solved General and Desktop
qcomboboxqt6qmouseeventsgaistqevent
8 Posts 5 Posters 1.3k 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.
  • HeerokNewbieH Offline
    HeerokNewbieH Offline
    HeerokNewbie
    wrote on last edited by
    #1

    I have two ComboBox. I want to disable second ComboBox when i click (Mouse Click) on first comboBox and same operation for other combobox. So is it possible? If yes so how ? Please check the images for better explanation.

    IMG_20220108_205601.jpg

    IMG_20220108_210038.jpg

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      What is the goal of that behaviour ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      HeerokNewbieH 1 Reply Last reply
      2
      • posktomtenP Offline
        posktomtenP Offline
        posktomten
        wrote on last edited by
        #3

        Hi!

        connect(ui->comboOne, QOverload<int>::of(&QComboBox::activated),
           [ = ]() {
               ui->comboTwo->setDisabled(true);
           });
           connect(ui->comboTwo, QOverload<int>::of(&QComboBox::activated),
           [ = ]() {
               ui->comboOne->setDisabled(true);
           });
        

        There may be a need for a way to reenable them again...

        posktomten

        1 Reply Last reply
        3
        • SGaistS SGaist

          Hi,

          What is the goal of that behaviour ?

          HeerokNewbieH Offline
          HeerokNewbieH Offline
          HeerokNewbie
          wrote on last edited by
          #4

          @SGaist I don't understand What is "goal of the behaviour" ? 😥
          I have already given as much information as I know.
          I want the second one combobox to be disabled automatically when I click on the first one combobox. Combobox does not have (isfocus()) function.

          Pl45m4P 1 Reply Last reply
          0
          • HeerokNewbieH HeerokNewbie

            @SGaist I don't understand What is "goal of the behaviour" ? 😥
            I have already given as much information as I know.
            I want the second one combobox to be disabled automatically when I click on the first one combobox. Combobox does not have (isfocus()) function.

            Pl45m4P Offline
            Pl45m4P Offline
            Pl45m4
            wrote on last edited by
            #5

            @HeerokNewbie

            @SGaist asked WHY you want to do that...
            This is very weird UX design... maybe there are other ways.
            What do you what to achieve in total?


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

            ~E. W. Dijkstra

            HeerokNewbieH 1 Reply Last reply
            3
            • Pl45m4P Pl45m4

              @HeerokNewbie

              @SGaist asked WHY you want to do that...
              This is very weird UX design... maybe there are other ways.
              What do you what to achieve in total?

              HeerokNewbieH Offline
              HeerokNewbieH Offline
              HeerokNewbie
              wrote on last edited by HeerokNewbie
              #6

              @Pl45m4 @SGaist I am making a software. In which there are two comboboxes and one pushbutton. And each combobox stores different file names of the user. So I want the function to first check which combobox is active whenever I click on pushbutton. And for this I have to disable one of the combobox first. and access the items of whichever combobox is active. The combobox also doesn't have isFocused() function so that I can check which combobox is active. Please tell me which function and class I have to use that whenever the user clicks on one of the comboboxes, that combobox becomes active and the other disabled.

              JonBJ 1 Reply Last reply
              0
              • HeerokNewbieH HeerokNewbie

                @Pl45m4 @SGaist I am making a software. In which there are two comboboxes and one pushbutton. And each combobox stores different file names of the user. So I want the function to first check which combobox is active whenever I click on pushbutton. And for this I have to disable one of the combobox first. and access the items of whichever combobox is active. The combobox also doesn't have isFocused() function so that I can check which combobox is active. Please tell me which function and class I have to use that whenever the user clicks on one of the comboboxes, that combobox becomes active and the other disabled.

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

                @HeerokNewbie said in How to disable Second QComboBox by clicking on the first QComboBox?:

                there are two comboboxes and one pushbutton
                So I want the function to first check which combobox is active whenever I click on pushbutton.

                If you wait for a click on a QPushButton (not shown in your picture), how will any of the comboboxes have focus at that time --- won't focus move to the pushbutton?

                Meanwhile did you try @posktomten's code above? Did that do what you want?

                HeerokNewbieH 1 Reply Last reply
                0
                • JonBJ JonB

                  @HeerokNewbie said in How to disable Second QComboBox by clicking on the first QComboBox?:

                  there are two comboboxes and one pushbutton
                  So I want the function to first check which combobox is active whenever I click on pushbutton.

                  If you wait for a click on a QPushButton (not shown in your picture), how will any of the comboboxes have focus at that time --- won't focus move to the pushbutton?

                  Meanwhile did you try @posktomten's code above? Did that do what you want?

                  HeerokNewbieH Offline
                  HeerokNewbieH Offline
                  HeerokNewbie
                  wrote on last edited by
                  #8

                  @JonB Yes ! and my problem is solved thank you @posktomten

                  1 Reply Last reply
                  0

                  • Login

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