Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. connecting string item of qlistwidget to my class
QtWS25 Last Chance

connecting string item of qlistwidget to my class

Scheduled Pinned Locked Moved General and Desktop
qlistwidgetitemconnectqt5.5.0
2 Posts 2 Posters 1.6k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • L Offline
    L Offline
    Lorence
    wrote on last edited by Lorence
    #1

    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

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      @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

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved