Results 1 to 20 of 38

Thread: subclass QLineEdit to have an index

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: subclass QLineEdit to have an index

    The OPs question makes more sense if you understand how Visual Basic 6 handled controls on a form. A form could have a number fully independent text boxes (equivalent of QLineEdit) each with an individual name as you would see in a Qt form. However, VB6 also had an upper limit on the number of controls on a form (256 IIRC). If you needed to exceed that then VB6 provided a method that could be used to provide a flyweight version of a control with single name and index to access many instances of that control type: a control array. That is, edit(1) referred to the first editor, edit(2) to the second, etc. but there was only one actual control object. Once the control gained an index its event handlers (like slots) were automagically passed an integer index number as their first argument.


    The most direct translation of that is to a list of QLineEdits and a QSignalMapper (but the behaviours also bear striking resemblance to the transient editor in item views). I guess that in Python th "control array" might look some like this (only passing knowledge of Python):
    Qt Code:
    1. self.TextBox = []
    2. for i in range(0, 1500):
    3. self.TextBox.append(new QLineEdit)
    4. layout.addWidget(self.TextBox[i])
    5.  
    6. # and later
    7. Str = TextBox[123].text()
    To copy to clipboard, switch view to plain text mode 
    Actually, the QSignalMapper docs have an almost complete example of the entire process including channelling signals from 1500 widgets through a single set of slots with an integer index.

  2. #2
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,233
    Thanks
    303
    Thanked 864 Times in 851 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: subclass QLineEdit to have an index

    The OPs question makes more sense if you understand how Visual Basic 6 handled controls on a form.
    And the OP seems to want to force Qt and Python to use the same semantics, even though it isn't possible using the syntax he is proposing. As we have already suggested, the closest thing to that is to use QSignalMapper, but that doesn't appear to satisfy the need to adhere to VB syntax. My head hurts from pounding it against the wall, so I'll leave it to the rest of you to carry on.

Similar Threads

  1. Replies: 0
    Last Post: 11th June 2013, 10:50
  2. Replies: 2
    Last Post: 15th April 2013, 06:33
  3. Index out of bounds in custom QLayout subclass
    By space_otter in forum Qt Programming
    Replies: 1
    Last Post: 5th October 2011, 20:23
  4. Replies: 1
    Last Post: 12th January 2011, 22:40
  5. Replies: 8
    Last Post: 12th February 2010, 02:41

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.