Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. how to specify no icon.source in TabBar

how to specify no icon.source in TabBar

Scheduled Pinned Locked Moved Solved QML and Qt Quick
5 Posts 3 Posters 491 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.
  • mzimmersM Offline
    mzimmersM Offline
    mzimmers
    wrote on last edited by
    #1

    Hi all -

    I have this passage:

    ListModel {
        id: prefsModel
        ListElement { name: "Profile && Accounts"; image: "" }
        ListElement { name: "Device"; image: ""}
        ListElement { name: "Site"; image: "" }
        ListElement { name: "BODY OF WATER"; image: "qrc:/icons/add.svg" }
    }
    
    Repeater {
        model: prefsModel
        Tabbutton_custom {
            text: qsTr(model.name)
            icon.source: model.image
            bgColor: auxTabBar.bgColor
            imageSize: auxTabBar.height / 2
        }
    }
    

    This works, but for each of the ListElements with empty strings for the image property, I get an error: "Unable to assign [undefined] to QUrl." What is the preferred method for doing this? (I actually customized TabButton, but left that out from this example, so I can modify that if appropriate.)

    Thanks...

    JoeCFDJ 1 Reply Last reply
    0
    • mzimmersM mzimmers

      Hi all -

      I have this passage:

      ListModel {
          id: prefsModel
          ListElement { name: "Profile && Accounts"; image: "" }
          ListElement { name: "Device"; image: ""}
          ListElement { name: "Site"; image: "" }
          ListElement { name: "BODY OF WATER"; image: "qrc:/icons/add.svg" }
      }
      
      Repeater {
          model: prefsModel
          Tabbutton_custom {
              text: qsTr(model.name)
              icon.source: model.image
              bgColor: auxTabBar.bgColor
              imageSize: auxTabBar.height / 2
          }
      }
      

      This works, but for each of the ListElements with empty strings for the image property, I get an error: "Unable to assign [undefined] to QUrl." What is the preferred method for doing this? (I actually customized TabButton, but left that out from this example, so I can modify that if appropriate.)

      Thanks...

      JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2

      @mzimmers said in how to specify no icon.source in TabBar:

      icon.source: model.image

      can not you check if model.image is empty or not? Set it if not empty.
      icon.source: model.image === "" ? Qt.resolvedUrl("") : model.image

      GrecKoG mzimmersM 2 Replies Last reply
      1
      • JoeCFDJ JoeCFD

        @mzimmers said in how to specify no icon.source in TabBar:

        icon.source: model.image

        can not you check if model.image is empty or not? Set it if not empty.
        icon.source: model.image === "" ? Qt.resolvedUrl("") : model.image

        GrecKoG Offline
        GrecKoG Offline
        GrecKo
        Qt Champions 2018
        wrote on last edited by
        #3
        This post is deleted!
        1 Reply Last reply
        0
        • JoeCFDJ JoeCFD

          @mzimmers said in how to specify no icon.source in TabBar:

          icon.source: model.image

          can not you check if model.image is empty or not? Set it if not empty.
          icon.source: model.image === "" ? Qt.resolvedUrl("") : model.image

          mzimmersM Offline
          mzimmersM Offline
          mzimmers
          wrote on last edited by
          #4

          @JoeCFD using your idea, I still get the error.

          mzimmersM 1 Reply Last reply
          0
          • mzimmersM mzimmers

            @JoeCFD using your idea, I still get the error.

            mzimmersM Offline
            mzimmersM Offline
            mzimmers
            wrote on last edited by mzimmers
            #5

            It turns out that @JoeCFD was right. The problem wasn't with my forming of the QString; it was that my code is a little more complicated than the snippet I posted above:

            Repeater {
                model: (navBar.tabIndex < 4) ? zoneModel : prefsModel
                Tabbutton_custom {
                    text: qsTr(model.name)
                    icon.source: (model === prefsModel && model.image !== "") ? model.image : Qt.resolvedUrl("")
                    bgColor: auxTabBar.bgColor
                    imageSize: auxTabBar.height / 2
                }
            }
            

            I'm trying to make the model selection dynamic, which seems to work, but my test for which model is in use isn't working right.

            I'll mark this as solved and open a new topic.

            Thanks...

            1 Reply Last reply
            0
            • mzimmersM mzimmers has marked this topic as solved on

            • Login

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