c++ - Make QListWidget only show 1 item -
i have created class inherits qlistwidget , meant stack of cards.
i have overloaded drag , drop functions allow card dragged table (another object of program) , stumble on problem.
the qlistwidget shows items (mainly because add them gui beginning).
so how goes: in mainwindow initialise cardpile object , fill shuffled vector of cards.
now want qlistwidget show 1 (but showing grid cards).
on drop remove item qlistwidget. have no idea if add , remove 1 card @ time (so shows 1 card ofcourse) in code.
public: tilestack(qwidget *parent = 0); void addcard(qpixmap pixmap, qpoint location); qpixmap showcard(); protected: void dragenterevent(qdragenterevent *event); void dragmoveevent(qdragmoveevent *event); void startdrag(qt::dropactions supportedactions); //in function remove current item
these functions in cardpile : qlistwidget.
so:
void tilestack::startdrag(qt::dropactions /*supportedactions*/) { qlistwidgetitem *item = currentitem(); qbytearray itemdata; qdatastream datastream(&itemdata, qiodevice::writeonly); qpixmap pixmap = qvariantvalue<qpixmap>(item->data(qt::userrole)); qpoint location = item->data(qt::userrole+1).topoint(); datastream << pixmap << location; qmimedata *mimedata = new qmimedata; mimedata->setdata("card", itemdata); qdrag *drag = new qdrag(this); drag->setmimedata(mimedata); drag->sethotspot(qpoint(pixmap.width()/2, pixmap.height()/2)); drag->setpixmap(pixmap); if (drag->exec(qt::moveaction) == qt::moveaction) delete takeitem(row(item)); //should make add next item here? , how should put here? }
because have vector of shuffled cards in mainwindow (where add cards in forloop).
or should make signal , slot connect between mainwindow , cardpile - when
delete takeitem(row(item));
is called emit signal says add next card list?
thanks feedback
you can use qstackwiget
(the first line of desription want ahieve) instead of qlistwidget.
Comments
Post a Comment