[Interest] Creating QML Component instances in C++

Gabriel M. Beddingfield gabrbedd at gmail.com
Mon Apr 2 06:50:32 CEST 2012


All:

I'm trying to make a container, similar to GridView.  I can set a delegate and create instances of them, but I can't seem to make them visible.  What am I doing wrong?

To illustrate my problem, I've set up a minimal example (attached) with a custom Component called "FourSquare."  It's supposed to lay out four of the delegates in a 2x2 grid.  The expected results of the program is to see 4 red squares.  However, I don't see them... all I see is the background.

void FourSquare::update_layout()
{
    int rows, cols, r, c;
    int x, y, m;
    QObject *obj;

    if (!m_delegate)
        return;

    rows = 2;
    cols = 2;
    m = 2; /* margin */
    y = 0;
    for (r = 0 ; r < rows ; ++r) {
        x = 0;
        for (c = 0 ; c < cols ; ++c) {
            if (!m_children[r][c]) {
                obj = m_delegate->create();
                obj->setParent(this);
            }
            obj->setProperty("x", x);
            obj->setProperty("y", y);
            obj->setProperty("width", m_cellWidth);
            obj->setProperty("height", m_cellHeight);
            x += m_cellWidth + m;
        }
        y += m_cellHeight + m;
    }
}

Thanks in advance!

-gabriel

p.s. I'm using Qt 4.7.4 on Ubuntu 11.10 (x86).
-------------- next part --------------
A non-text attachment was scrubbed...
Name: delegates.tar.bz2
Type: application/x-bzip
Size: 2602 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20120401/3e59d5d2/attachment.bin>


More information about the Interest mailing list