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.
  • H Offline
    H Offline
    HeerokNewbie
    wrote on 8 Jan 2022, 15:50 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 8 Jan 2022, 18:21 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

      H 1 Reply Last reply 9 Jan 2022, 05:14
      2
      • P Offline
        P Offline
        posktomten
        wrote on 8 Jan 2022, 23:04 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
        • S SGaist
          8 Jan 2022, 18:21

          Hi,

          What is the goal of that behaviour ?

          H Offline
          H Offline
          HeerokNewbie
          wrote on 9 Jan 2022, 05:14 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.

          P 1 Reply Last reply 9 Jan 2022, 06:11
          0
          • H HeerokNewbie
            9 Jan 2022, 05:14

            @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.

            P Offline
            P Offline
            Pl45m4
            wrote on 9 Jan 2022, 06:11 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

            H 1 Reply Last reply 9 Jan 2022, 06:44
            3
            • P Pl45m4
              9 Jan 2022, 06:11

              @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?

              H Offline
              H Offline
              HeerokNewbie
              wrote on 9 Jan 2022, 06:44 last edited by HeerokNewbie 1 Sept 2022, 06:49
              #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.

              J 1 Reply Last reply 9 Jan 2022, 08:04
              0
              • H HeerokNewbie
                9 Jan 2022, 06:44

                @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.

                J Offline
                J Offline
                JonB
                wrote on 9 Jan 2022, 08:04 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?

                H 1 Reply Last reply 9 Jan 2022, 08:25
                0
                • J JonB
                  9 Jan 2022, 08:04

                  @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?

                  H Offline
                  H Offline
                  HeerokNewbie
                  wrote on 9 Jan 2022, 08:25 last edited by
                  #8

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

                  1 Reply Last reply
                  0

                  1/8

                  8 Jan 2022, 15:50

                  • Login

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