Update ListView from another

103 views Asked by At

I'm making a card game which has 4 slots of cards with a capacity of 5 each. I'm using ListView to represent each slot. Let me explain code first then my problem.

class ClientCard : public QObject
{
    Q_OBJECT
    int code;       // card code
    int location;   // zone in which card is located
    ...
    ClientCard* equipTarget;
    QSet<ClientCard*> equipped;
    ...
};

class ClientCardModel : public QAbstractListModel 
{
    enum CardRoles {
        CodeRole = Qt::UserRole + 1, 
        LocationRole
        }
    ...
    QList<ClientCard*> m_list;
};

ClientCardModel has a list of ClientCard for ListView and roles to transfer code and other member to QML. Let me represent each ListView with a zone (like zone1, zone2 etc). In the game a card can be equipped with other cards in other zones. Cards equipped on a card is stored in QSet<> equipped and a card equipping a card is stored in equipTarget. When one hover over a card in a zone, cards equipping it in other zones should be highlighted using an image till the mouse remains on the card.

Any idea is appreciated.

1

There are 1 answers

7
skypjack On

Let me know if it fits your requirements.

Reply reviewed, just woken up, sorry. :-)

You can have delegates in your view covered with MouseArea. Once a card is hovered, you can set an internal parameter accessible from within the delegate that reflects the state of the equipped card (hovered/not hovered). The delegate itself will react to the change of that parameter, so that each other card equipping the hovered one would react as well.

In other therms, hovering should change some exported parameter (this can be achieved maybe by means of a MouseArea) and delegates should be designed so that they react on that parameter changes to show whatever you want.