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
Forum Update on Monday, May 27th 2025

QML update image

Scheduled Pinned Locked Moved QML and Qt Quick
2 Posts 1 Posters 1.6k 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.
  • W Offline
    W Offline
    wimw
    wrote on 11 Jul 2012, 14:16 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 11 Jul 2012, 14:18 last edited by
      #2

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

      1 Reply Last reply
      0

      1/2

      11 Jul 2012, 14:16

      • Login

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