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. Visibility Toggling
Forum Updated to NodeBB v4.3 + New Features

Visibility Toggling

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 3 Posters 1.8k 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.
  • G Offline
    G Offline
    GoldRatio
    wrote on last edited by
    #1

    Is it possible to toggle the visibility of an Item such as a SpinBox using a ComboBox?
    I want the Item (Spin Box) to show up when certain selections in a ComboBox, and not show up for other choices.

    Thanks!

    jsulmJ 1 Reply Last reply
    0
    • G GoldRatio

      Is it possible to toggle the visibility of an Item such as a SpinBox using a ComboBox?
      I want the Item (Spin Box) to show up when certain selections in a ComboBox, and not show up for other choices.

      Thanks!

      jsulmJ Offline
      jsulmJ Offline
      jsulm
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @GoldRatio http://doc.qt.io/qt-5/qwidget.html#visible-prop

      https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        GoldRatio
        wrote on last edited by
        #3

        @jsulm I still don't get how to do it. I tried using a switch statement but it doesn't work. This is what I have so far.

        ComboBox{
        id: comboBox
        textRole: "choice"
        model: ListModel{
        ListElement{
        choice: "visible"
        value: 0
        }
        ListElement{
        choice:"invisible"
        value: 1
        }
        }
        }

        SpinBox{
        id: spin
        visible:{
        switch(comboBox.currentIndex)
        {
        case 0: setVisible(true)
        case 1: set Visible(false)
        }
        }
        }
        }
        It gives me a warning saying that there is an undetermined non-empty case block

        Thanks!

        jsulmJ 1 Reply Last reply
        0
        • G GoldRatio

          @jsulm I still don't get how to do it. I tried using a switch statement but it doesn't work. This is what I have so far.

          ComboBox{
          id: comboBox
          textRole: "choice"
          model: ListModel{
          ListElement{
          choice: "visible"
          value: 0
          }
          ListElement{
          choice:"invisible"
          value: 1
          }
          }
          }

          SpinBox{
          id: spin
          visible:{
          switch(comboBox.currentIndex)
          {
          case 0: setVisible(true)
          case 1: set Visible(false)
          }
          }
          }
          }
          It gives me a warning saying that there is an undetermined non-empty case block

          Thanks!

          jsulmJ Offline
          jsulmJ Offline
          jsulm
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @GoldRatio Now I see you're using QML - you should mention this.
          I'm not a QML expert, but shouldn't there be something like:

          switch(comboBox.currentIndex)
          {
          case 0: setVisible(true);
                  break;
          case 1: setVisible(false);
                  break;  
          default: setVisible(true);
                   break;
          }

          https://forum.qt.io/topic/113070/qt-code-of-conduct

          J.HilkJ 1 Reply Last reply
          1
          • jsulmJ jsulm

            @GoldRatio Now I see you're using QML - you should mention this.
            I'm not a QML expert, but shouldn't there be something like:

            switch(comboBox.currentIndex)
            {
            case 0: setVisible(true);
                    break;
            case 1: setVisible(false);
                    break;  
            default: setVisible(true);
                     break;
            }
            J.HilkJ Offline
            J.HilkJ Offline
            J.Hilk
            Moderators
            wrote on last edited by
            #5

            @jsulm said in Visibility Toggling:

            @GoldRatio Now I see you're using QML - you should mention this.
            I'm not a QML expert, but shouldn't there be something like:

            switch(comboBox.currentIndex)
            {
            case 0: setVisible(true);
                    break;
            case 1: setVisible(false);
                    break;  
            default: setVisible(true);
                     break;
            }
            

            close, but not quite, this should do it:

            //inside combobox
            onCurrentIndexChanged:{
               switch(currentIndex)
               {
                case 0: spin.visible = true;
                     break;
                case 1: spin.visible = false;
                     break;  
                default: spin.visible = true;
                      break;
                }
            }
            

            Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


            Q: What's that?
            A: It's blue light.
            Q: What does it do?
            A: It turns blue.

            1 Reply Last reply
            1
            • G Offline
              G Offline
              GoldRatio
              wrote on last edited by
              #6
              This post is deleted!
              1 Reply Last reply
              0
              • G Offline
                G Offline
                GoldRatio
                wrote on last edited by
                #7

                Thanks! I figured out a different way and forgot to check the forum. I used:

                onCurrentIndexChanged:{
                visible: {
                switch(currentIndex)
                {
                case 0: return true;
                case 1: return false;
                default: return false;
                }
                }
                }

                Thanks for all of the help tough!

                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