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. In QML how can I work with an inverted font without resizing my window

In QML how can I work with an inverted font without resizing my window

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
1 Posts 1 Posters 155 Views
  • 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.
  • A Offline
    A Offline
    AI_Messiah
    wrote on last edited by
    #1

    So what I have is a simple clock with a font where the foreground and background colors are reversed. I want the window to have the color white and the inner time string to be black. Anyway this is my code:

    import QtQuick 2.12
    import QtQuick.Window 2.12
    import QtQuick.Controls 2.5
    import QtQml 2.12
    Window {
        width: 640
        height: 480
        visible: true
        title: qsTr("Clock")
    
        property string mytime: ""
        property bool isAm: true
        Timer{
            interval: 250; running: true; repeat: true
            onTriggered:{
                mytime = Qt.formatDateTime(new Date(), "hh:mm:ss")
                if (Qt.formatDateTime(new Date(), "AP") == "AM"){
                    isAm = true
                }else{
                    isAm = false
                }
            }
            
        }
        Rectangle{
            anchors.fill: parent
            color: "white"
        }
    
        Rectangle{
            x: mylab.x
            y: mylab.y
            width: mylab.width
            height: mylab.height
            anchors.fill: parent
            color: "black"
        }
        Label{
            id: mylab
            x: parent.width / 2 - width / 2  + 26
            y: parent.height / 2 - height / 2
            font.family: "7 SEGMENTAL DIGITAL DISPLAY"
            font.pixelSize: 128
            text: mytime
            color: "white"
    
        }
    
        Canvas{
            id: mycanvas
    
            width: 50
            height: mylab.height
            x: mylab.x - 52
            y: parent.height / 2 - height / 2
            onPaint: {
                var ctx = getContext("2d");
                ctx.fillStyle = Qt.rgba(1, 1, 1, 1);
                ctx.fillRect(0, 0, width, height);
                ctx.fillStyle = Qt.rgba(0, 0, 0, 1);
                var siz = 20
                var locx = width / 2 - siz / 2
                var locy
                if (isAm){
                    locy = height / 4 - siz / 2
                }else{
                    locy = height * .75 - siz / 2
                }
                ctx.ellipse(locx, locy, siz, siz)
                ctx.fill()
            }
        }
    
     }
    
    
    1 Reply Last reply
    0

    • Login

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