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. pyQt How do I get a widget from a QListWidgetItem?
QtWS25 Last Chance

pyQt How do I get a widget from a QListWidgetItem?

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 3 Posters 2.9k 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.
  • robbiecooperR Offline
    robbiecooperR Offline
    robbiecooper
    wrote on last edited by
    #1

    hi All

    I have used setItemWidget() to put a custom widget in a QListWidgetItem, how do I get a reference to it afterwards?

    Also, related question- my QListWidget is no longer responding to mouse events etc. But it's easy to get mouse events from the custom widget. Is there a way of adapting the QListWidget to use its standard functions such as currentItem()? Or would teh normal process be to connect signals in the custom QWidget to slots in the GUI?

    m.sueM 1 Reply Last reply
    0
    • robbiecooperR robbiecooper

      hi All

      I have used setItemWidget() to put a custom widget in a QListWidgetItem, how do I get a reference to it afterwards?

      Also, related question- my QListWidget is no longer responding to mouse events etc. But it's easy to get mouse events from the custom widget. Is there a way of adapting the QListWidget to use its standard functions such as currentItem()? Or would teh normal process be to connect signals in the custom QWidget to slots in the GUI?

      m.sueM Offline
      m.sueM Offline
      m.sue
      wrote on last edited by
      #2

      Hi @robbiecooper

      There is a corresponding function QWidget * itemWidget(QListWidgetItem *item) const that you should be able to use.

      -Michael.

      robbiecooperR 1 Reply Last reply
      1
      • m.sueM m.sue

        Hi @robbiecooper

        There is a corresponding function QWidget * itemWidget(QListWidgetItem *item) const that you should be able to use.

        -Michael.

        robbiecooperR Offline
        robbiecooperR Offline
        robbiecooper
        wrote on last edited by
        #3

        @m.sue Great thanks! Do you know why the QListWidget no longer detects mouse events over the QListWidgetitem?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          That's because you put a widget in it which means it's that widget that will get the events.

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          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