Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. How to write text to listWidget?
Forum Updated to NodeBB v4.3 + New Features

How to write text to listWidget?

Scheduled Pinned Locked Moved Unsolved Qt for Python
2 Posts 2 Posters 198 Views 1 Watching
  • 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.
  • A Offline
    A Offline
    Anonymous_Banned275
    wrote on last edited by
    #1

    I realize this is not the forum to ask basic Python questions, but I have no access to another Python forum.

    I have a simple code to clear listWidget , but I cannot figure out the correct syntax to add simple text to listWidget.

    Here is my code

                self.pushButton_InitializeTRACE.clicked.connect(self.listWidget.clear)
                item_TEST = " Initialize debug TRACE"
                # self.pushButton_InitializeTRACE.clicked.connect(self.listWidget.setToolTip(" Initialize debug TRACE "))
                self.pushButton_InitializeTRACE.clicked.connect(self.listWidget.addItem(self.item_TEST) )
    
    
    and its resulting error :
    
    

    File "/mnt/07b7c3f8-0efb-45ab-8df8-2a468771de1f/NANO_WORK/src/NanoVNASaver/NanoVNASaver.py", line 348, in init
    "DISPLAY_FORM": TDRWindow_COPY(self), # copy of TDRWindow
    File "/mnt/07b7c3f8-0efb-45ab-8df8-2a468771de1f/NANO_WORK/src/NanoVNASaver/Windows/TRACE_FORM.py", line 272, in init
    self.pushButton_InitializeTRACE.clicked.connect(self.listWidget.addItem(self.item_TEST) )
    AttributeError: 'TDRWindow_COPY' object has no attribute 'item_TEST'

    In simple terms 
    I can "clear " the listWidget, but I cannot add SIMPLE text to it. 
    
    MrsGoogle showed me how to add items from a list, but I want to add SINGLE  line of text.
    

    The above is a copy from word processor so it may not meet code formatting.
    If that is a problem , please IGNORE the post - there is no need to inform me about "code formatting" - it does not solve my code problem.

    It would be nice if somebody just wrote correct code and give some explanation why my syntax is wrong .

    wrong syntax:
    self.pushButton_InitializeTRACE.clicked.connect(self.listWidget.addItem(self.item_TEST) )

    Correct syntax here

    .....
    your syntax IS WRONG BECAUSE HERE

    ....

    Thanks

    JonBJ 1 Reply Last reply
    0
    • A Anonymous_Banned275

      I realize this is not the forum to ask basic Python questions, but I have no access to another Python forum.

      I have a simple code to clear listWidget , but I cannot figure out the correct syntax to add simple text to listWidget.

      Here is my code

                  self.pushButton_InitializeTRACE.clicked.connect(self.listWidget.clear)
                  item_TEST = " Initialize debug TRACE"
                  # self.pushButton_InitializeTRACE.clicked.connect(self.listWidget.setToolTip(" Initialize debug TRACE "))
                  self.pushButton_InitializeTRACE.clicked.connect(self.listWidget.addItem(self.item_TEST) )
      
      
      and its resulting error :
      
      

      File "/mnt/07b7c3f8-0efb-45ab-8df8-2a468771de1f/NANO_WORK/src/NanoVNASaver/NanoVNASaver.py", line 348, in init
      "DISPLAY_FORM": TDRWindow_COPY(self), # copy of TDRWindow
      File "/mnt/07b7c3f8-0efb-45ab-8df8-2a468771de1f/NANO_WORK/src/NanoVNASaver/Windows/TRACE_FORM.py", line 272, in init
      self.pushButton_InitializeTRACE.clicked.connect(self.listWidget.addItem(self.item_TEST) )
      AttributeError: 'TDRWindow_COPY' object has no attribute 'item_TEST'

      In simple terms 
      I can "clear " the listWidget, but I cannot add SIMPLE text to it. 
      
      MrsGoogle showed me how to add items from a list, but I want to add SINGLE  line of text.
      

      The above is a copy from word processor so it may not meet code formatting.
      If that is a problem , please IGNORE the post - there is no need to inform me about "code formatting" - it does not solve my code problem.

      It would be nice if somebody just wrote correct code and give some explanation why my syntax is wrong .

      wrong syntax:
      self.pushButton_InitializeTRACE.clicked.connect(self.listWidget.addItem(self.item_TEST) )

      Correct syntax here

      .....
      your syntax IS WRONG BECAUSE HERE

      ....

      Thanks

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by JonB
      #2

      @AnneRanch said in How to write text to listWidget?:

      self.pushButton_InitializeTRACE.clicked.connect(self.listWidget.addItem(self.item_TEST) )

      Try:

      self.pushButton_InitializeTRACE.clicked.connect( lambda: self.listWidget.addItem(self.item_TEST) )
      

      You need a lambda here for the slot, that's how you specify inline code like you have to execute rather than connecting to a method.

      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