久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

在 Qt QML 中為許多文本元素指定字體

Specifying font for many Text-elements in Qt QML(在 Qt QML 中為許多文本元素指定字體)
本文介紹了在 Qt QML 中為許多文本元素指定字體的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我有一個(gè)通過 QML 文件指定的小部件.這個(gè)小部件包含一個(gè)頂級(jí)Rectangle,它包含兩個(gè)Columns.這些 Columns 中的每一個(gè)都包含許多 Text 元素.這個(gè) QML 小部件包含在 C++ 中 QDeclarativeView 的子類中.

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

我想為每個(gè) Text 元素指定字體.今天我通過指定頂級(jí)屬性來做到這一點(diǎn):

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"

并將每個(gè) Text 元素綁定到這些屬性:

and bind each Text-elements to these properties:

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

這不是很優(yōu)雅,每次我需要支持新的東西時(shí)都需要添加新的字段(例如帶下劃線的字體).我無法聲明 font 類型的屬性并綁定到它(小部件為空白,qmlviewer 警告屬性后的預(yù)期類型").

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").

是否有更好的方法為所有 Text 元素指定字體?

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

注意!我正在手寫 QML 文件.

Note! I'm handwriting the QML files.

推薦答案

另一種可能是編寫一個(gè)新的 QML 組件,它繼承自 Text 并默認(rèn)設(shè)置一些屬性:

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
}

ma??in.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"
            }
        }
    }
}

這篇關(guān)于在 Qt QML 中為許多文本元素指定字體的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請(qǐng)聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

How can I read and manipulate CSV file data in C++?(如何在 C++ 中讀取和操作 CSV 文件數(shù)據(jù)?)
In C++ why can#39;t I write a for() loop like this: for( int i = 1, double i2 = 0; (在 C++ 中,為什么我不能像這樣編寫 for() 循環(huán): for( int i = 1, double i2 = 0;)
How does OpenMP handle nested loops?(OpenMP 如何處理嵌套循環(huán)?)
Reusing thread in loop c++(在循環(huán) C++ 中重用線程)
Precise thread sleep needed. Max 1ms error(需要精確的線程睡眠.最大 1ms 誤差)
Is there ever a need for a quot;do {...} while ( )quot; loop?(是否需要“do {...} while ()?環(huán)形?)
主站蜘蛛池模板: 国产91丝袜在线18 | 激情视频中文字幕 | 国产精品九九视频 | 少妇一区在线观看 | 综合久久综合久久 | 91色视频在线观看 | 福利国产| 成人精品久久日伦片大全免费 | 国产精品综合视频 | 亚洲精品不卡 | 久操伊人 | 男女在线网站 | 日韩成人影院 | 国产精品久久久久久久久免费丝袜 | 91视频导航 | 国产成人免费网站 | 91欧美激情一区二区三区成人 | 国产一二区视频 | 亚洲人va欧美va人人爽 | 国产精品视频观看 | 欧美日韩中文国产一区发布 | 国外成人在线视频 | 欧美一区二区三区在线观看视频 | 亚洲精品久久嫩草网站秘色 | 91在线视频观看免费 | 国产精品美女 | 色综合久久久 | 亚洲欧美一区二区三区国产精品 | 国产成人精品免费视频 | 日韩欧美中文在线 | 欧美在线视频二区 | 欧美色性| 天堂一区在线 | 久久久日韩精品一区二区三区 | 综合五月婷 | 99久久久久久 | 丁香婷婷综合激情五月色 | 中文字幕 欧美 日韩 | 国产精品久久久久久一区二区三区 | 欧美日韩免费在线 | 在线日韩视频 |