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. use of font property in TabBar
Forum Updated to NodeBB v4.3 + New Features

use of font property in TabBar

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 2 Posters 365 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.
  • M Offline
    M Offline
    mzimmers
    wrote on 17 Nov 2022, 18:56 last edited by
    #1

    Hi all -

    I have a general purpose component that customizes TabButton. I need to be able to pass to it things like font family, weight, etc. This is slightly complicated by the fact that my platform is Windows, which doesn't support variable fonts.

    I can replicate the problem in the example below. From the docs, this code looks like it should be correct:

    import QtQuick
    import QtQuick.Controls
    
    ApplicationWindow {
        visible: true
        width: 800
        height: 480
    
        TabBar {
            id: navTabs
            property font myFont: {
                family: "Helvetica"
                weight: Font.DemiBold
        }
            property int fontWeight: navTabs.myFont.weight
    
            TabButton {
                font.weight: navTabs.myFont.weight
                text: font.weight
            }
            TabButton {
                font.weight: parent.myFont.weight
                text: navTabs.fontWeight
            }
        }
    }
    

    But at runtime it's objecting to my line:

     weight: Font.DemiBold
    

    The error is Unable to assign int to QFont. Can someone tell me what I'm doing wrong?

    Thanks...

    1 Reply Last reply
    0
    • J Offline
      J Offline
      JoeCFD
      wrote on 17 Nov 2022, 19:03 last edited by
      #2

      can you try

      
              TabButton {
                  font: navTabs.myFont
                 font.weight: Font.DemiBold
              }
      
      M 1 Reply Last reply 17 Nov 2022, 19:27
      0
      • J JoeCFD
        17 Nov 2022, 19:03

        can you try

        
                TabButton {
                    font: navTabs.myFont
                   font.weight: Font.DemiBold
                }
        
        M Offline
        M Offline
        mzimmers
        wrote on 17 Nov 2022, 19:27 last edited by
        #3

        @JoeCFD doesn't like that -- I get an error: Property has already been assigned a value.

        I'm wondering whether a font property might not be the wrong way to go here - it doesn't accept most of the settings you can put in a font type. All I'm trying to do is find a way to pass parameters to my custom TabButton that I can use to format the button text - I seem to be going about it wrong.

        1 Reply Last reply
        0
        • M Offline
          M Offline
          mzimmers
          wrote on 17 Nov 2022, 19:47 last edited by mzimmers
          #4

          Through some experimentation, I discovered this:

          import QtQuick
          import QtQuick.Controls
          
          ApplicationWindow {
              visible: true
              width: 800
              height: 480
          
              TabBar {
                  id: navTabs
                  property font myFont: Qt.font({
                      family: "Helvetica",
                      weight: Font.DemiBold,
                      pixelSize: 48
                  })
          
                  TabButton {
                      width: 200
                      font: navTabs.myFont
                      text: font.weight + " " + font.pixelSize
                  }
                  TabButton {
                      font.family: navTabs.myFont.family
                      font.weight: Font.Light
                      font.pixelSize: navTabs.myFont.pixelSize
                      text: font.weight + " " + font.pixelSize
                  }
              }
          }
          

          The first TabButton references the TabBar font property as a unit, and as such, can't modify any of the fields (like weight). The second TabButton, though, only uses fields within the font property, and can set whatever it wants.

          I did uncover another problem here, though - this only works if the TabButtons explicitly reference navTabs. If I try to use parent instead, I get errors suggesting that the parent is undefined.

          In my example, is the TabBar not the parent of the TabButtons?

          EDIT:

          According to this, the answer is no. Any ideas on how to deal with this?

          EDIT 2:

          My original question is answered, so I'll mark this solved and start a new topic.

          1 Reply Last reply
          0

          1/4

          17 Nov 2022, 18:56

          • Login

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