Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7019575
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T23:12:04+00:00 2026-05-27T23:12:04+00:00

I have a widget specified through a QML file. This widget contains a top

  • 0

I have a widget specified through a QML file. This widget contains a top levelRectangle which contains two Columns. Each of these Columns contains many Text-elements. This QML widget is wrapped in a subclass of QDeclarativeView in C++.

I want to specify the font for each of these Text-elements. Today I do this by specifying top-level properties:

property string fontfamily: "Arial"
property bool fontbold: false
property bool fontitalic: false
property int fontpixelsize: 11
property string fontcolor: "White"

and bind each Text-elements to these properties:

Text
{   
    color: fontcolor
    font.family: fontfamily
    font.bold: fontbold
    font.italic: fontitalic
    font.pixelSize: fontpixelsize
    ...
}

This isn’t very elegant and new fields needs to be added every time I need support for something new (e.g. underlined fonts). I have not been able to declare a property of type font and bind to this instead (widget is blank and qmlviewer warns about “expected type after property”).

Is there a better way to specify a font for all Text-elements?

Note! I’m handwriting the QML files.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T23:12:05+00:00Added an answer on May 27, 2026 at 11:12 pm

    Another possibility is to write a new QML component, that inherits from Text an sets some properties by default:

    StyledText.qml

    import QtQuick 1.0
    
    Text {
        // set default values
        color: "blue"
        font.family: "Arial"
        font.bold: true
        font.italic: true
        font.pixelSize: 12
    }
    

    main.qml

    import QtQuick 1.0
    
    Rectangle {
        Row {
            spacing: 10
    
            Column {
                StyledText {
                    text: "Foo1"
                }
                StyledText {
                    text: "Bar1"
                }
                StyledText {
                    text: "Baz1"
                }
            }
    
            Column {
                StyledText {
                    text: "Foo2"
                }
                StyledText {
                    text: "Bar2"
                }
                StyledText {
                    text: "Baz2"
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this widget: $this->setWidget('slug', new sfWidgetFormDoctrineChoice(array('model' => 'MyTable', 'method' => 'myMethod', 'key_method' =>
I am using a fictional example for this. Say, I have a Widget class
I have a JavaScript widget which provides standard extension points. One of them is
I have two JQuery widgets, one is a sort of 'main' widget, the other
I have a widget that acts as a launcher on the home screen. How
I have a widget that supposed to call an Activity of the main app
Let's say that I have a widget that displays summary information about how many
I have a UI widget that needs to be put in an IFRAME both
We have a UI widget on our main UI that uses JavaScript to respond
I have a TextEdit widget in PyQt that I use to print out a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.