Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Pixel accuracy



  • Hi

    I was wondering if I am assigning value to the height of rectangle as

    height:99.80
    

    what will happen with pixels?
    will the last pixel take 0.80 as value?
    I am working on code where pixel accuracy is very important so just want to know for above case will it take 99.80 as value or 100 as value or 99 as a value for height.

    Thanks
    Ashish Ajgaonkar


  • Moderators

    Try it out... My guess is that it will be rounded to 100, but the best solution is to just try :-) Plus maybe check the sources.



  • hi @sierdzio
    I wrote this program to get some clue

    import QtQuick 2.9
    import QtQuick.Window 2.2
    Window {
        visible: true
        width: 640
        height: 480
        title: qsTr("Hello World")
        property double size:99.5
        Rectangle
        {
            id: rect_one
            color:"RED"
            height:size
            width:100 
        }   
        Rectangle
        {
            id:rect_two
            color:"Blue"
            height:100
            width:100
            x:300
            MouseArea
            {
                anchors.fill:parent
                onClicked:{
                    console.log(rect_one.height)
                }
                
            }
        }
    }
    

    Here I am setting property double size:99.5 and assigning size to height of rect_one and on mouse clicked I am fetching height of rect_one Like this console.log(rect_one.height)

    Solution for this is

    QML debugging is enabled. Only use this in a safe environment.
    qml: 99.5
    

    So is this the right way to confirm the above case?
    as it is returning 99.5 can I claim that 99.5 pixel is the height ?


  • Moderators

    Place one rectangle on top of the other to see if there is any real difference in size. QML engine will report the dimension you set, but when displayed, it's not possible to display half of a pixel (well maybe it is, perhaps, with antialiasing), so it's likely that an approximation is made.



  • Hi @ashajg ,

    when you give the height or width of Rectangle,they are rounded of to the nearest value that is,
    if height <= 99.5 then height = 99
    if height > 99.5 then height = 100

    here is a sample code for that:-

     Rectangle {
        height: 100
        width: 100
        color: "transparent"
        border.color: "black"
        anchors.centerIn: parent
    
        Rectangle {
            height: 99.5
            width: 99.5
            color: "red"
    
            Text {
                text: parent.height
                anchors.centerIn: parent
            }
        }
    }
    

    Here are few samples output images attached:-

    0_1551946581624_Rect(99.1).PNG

    0_1551946595436_Rect(99.5).PNG

    0_1551946606655_Rect(99.8).PNG

    0_1551946613479_Rect(100).PNG


  • Moderators

    This is something, that could also be highly related to the display you're using.

    Phones for example tend to group pixels together (group of 4 or 9) you yourself will only operate on the reduced width and height, but drawing directly relates to the actual pixels.

    If I remember that correctly.





  • You are welcome :-) @ashajg , can you mark [SOLVED] to thread title!


Log in to reply