QML update image



  • Hi,

    I'm fairly new to QML and Qt in general and have encountered my first real problem.

    I'm trying to create a checkbox which has 3 positions.

    QML:
    @Rectangle {
    width: 300; height: 200
    CheckMark {
    id: a
    width: 15; height: 15
    x: 10; y: 10
    status: CheckMark.Empty;

            onStatusChanged: {
    
                console.log("changed a");
                b.status = status;
            }
    
    MouseArea {
        anchors.fill: parent;
        onClicked: { a.checkStatus(); console.log(a.status); }
    }
    

    }@

    The function checkStatus will change the status of the checkbox:

    @void CheckMark::setStatus(const Status &status)
    {
    if (m_status != status)
    {
    m_status=status;

        this->update();
        emit statusChanged();
    }
    

    }@

    The checkbox itself is drawn by the painter:
    @void CheckMark::paint(QPainter *painter, const QStyleOptionGraphicsItem *, QWidget *widget)
    {

    switch(m_status)
    {
    case Full:
        painter->drawImage(QRect(m_x, m_y, m_width, m_height), checkboxFullImg);
        break;
    case Empty:
        painter->drawImage(QRect(m_x, m_y, m_width, m_height), checkboxEmptyImg);
        break;
    case InBetween:
        painter->drawImage(QRect(m_x, m_y, m_width, m_height), checkboxInBetweenImg);
        break;
    }
    

    }@

    The problem is when the checkbox is clicked the status changes, but the image does not refresh.

    What am i missing here?



  • Ah, the image does refresh, however only when I manually change the window size ...


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.