Qt World Summit: Submit your Presentation

connecting string item of qlistwidget to my class

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


    qlistwidget items:

    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

  • Lifetime Qt Champion

    @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
    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

    then you can always know which is which even if rearranged.
    see here for how to take index out also