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. QML update image
Qt 6.11 is out! See what's new in the release blog

QML update image

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.7k Views 1 Watching
  • 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.
  • W Offline
    W Offline
    wimw
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • W Offline
      W Offline
      wimw
      wrote on last edited by
      #2

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

      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