จากโปรเจคแสดงจำนวนไลค์ในแฟนเพจ ที่เห็นใน Raspberry Pi 66 Club ก็เลยมีความคิดที่จะทำบ้างโดยใช้ RaspberryPi + QML และอยากจะทำให้มันแสดงผลตัวเลขออกมาในรูปขอตัวเลขแบบ Character LCD หรือไม่ก็ 7-Segment ซึ่งตอนแรกตั้งใจว่าจะใช้ภาพในการแสดงผล แต่ดูแล้วต้องการจัดการอีกเยอะ ก็เลยลองหา font ที่แสดงผลเป็น Character LCD หรือ 7-Segment ดูก็เจอในเว็ปนี้ http://www.dafont.com จากนั้นก็ใช้ element FontLoader เพื่อโหลด Font เข้ามาใช้ใน QML ครับ
หลักๆ ของ FontLoader ก็ไม่มีอะไรมากครับ properties source ก็เป็นชื่อของไฟล์ font ที่จะนำมาใช้ และเวลาที่ใช้งานใน Text element ก็แค่
font.family: my_font_1.name;
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
QML FontLoader | |
Author : MaIII Themd | |
Website : http://miiniq.blogspot.com | |
FB : http://www.facebook.com/PiShared | |
Env : Qt 5.0.2 clang 64 bit OSX 10.8.4 | |
*/ | |
import QtQuick 2.0 | |
Rectangle { | |
width: 700 | |
height: 300 | |
color : "black"; | |
FontLoader | |
{ | |
id : my_font_1; | |
source: "./fonts/EHSMB.TTF" | |
} | |
FontLoader | |
{ | |
id : my_font_2; | |
source: "./fonts/DS-DIGIT.TTF" | |
} | |
Text | |
{ | |
id : txt_show_1 | |
text : "http://miiniq.blogspot.com" | |
font.family: my_font_1.name; | |
font.pixelSize: 40; | |
anchors.horizontalCenter: parent.horizontalCenter; | |
anchors.top: parent.top; | |
anchors.topMargin: 80; | |
color : "#00FF00" | |
} | |
Text | |
{ | |
id : txt_show_2 | |
text : "http://miiniq.blogspot.com" | |
font.family: my_font_2.name; | |
font.pixelSize: 55; | |
anchors.horizontalCenter: parent.horizontalCenter; | |
anchors.top: txt_show_1.top; | |
anchors.topMargin: 80; | |
color : "#FF0000" | |
} | |
} | |
<< Qt 5.0 Programming VII : Animation part II
>> Qt 5.0 Programming IX : Anchor
0 ความคิดเห็น:
แสดงความคิดเห็น