connecting string item of qlistwidget to my class



  • is it possible to connect a string item of qlistwidget to my class?

    example:

    qlistwidget items:
    "Item1"
    "Item2"

    connect(thestringofthefirstitemofqlistwidget,signal(),myclass,slot()); // connects "Item1" to myclass.
    so now "item1" is connected to myclass, anytime "Item1" moved to any index of qlistwidget, it will still be connected to myclass


  • Qt Champions 2016

    @Lorence said:

    Hi when you add "xxxx" to a qlistwidget
    you are adding a QListWidgetItem.

    While you can subclass QListWidgetItem and make your own
    that has signals, it would not do you so much good as

    it would never never emit such signal unless you also made it do
    so when something happen to it. (overriding some of its functions)

    So It all depends what you are trying to do.
    If you just want to know its no 1,2,3 etc, even if moved
    then
    you can insert that info into the QListWidgetItem using the
    void QListWidgetItem::setData(int role, const QVariant & value)

    something like
    QListWidgetItem * item=new QListWidgetItem("item1") ;
    item->setData(Qt::UserRole, 1); // or 2 for item 2 etc
    list->addItem(item)

    then you can always know which is which even if rearranged.
    see here for how to take index out also
    http://stackoverflow.com/questions/7136818/can-i-store-some-user-data-in-every-item-of-a-qlistwidget


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.