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. Is that possible access default QLineEdit used in QListWidget::editItem() ?

Is that possible access default QLineEdit used in QListWidget::editItem() ?

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

    I have very simple case where I use QListWidget. But I need validate entered strings in some manner. If they are not Ok - then editing must continue. I understand that I can turn to model/view and implement my own ItemDelegate. Then I have create another QLineEdit and setValidator() for it. But this looks too complicated for this simple thing where text just needed to be checked. And there is already code for QLineEdit in QListWidget. Is that possible get pointer to this editor? I would just setValidate there and so on...

    Later I'll need different validation in some different QListWidget-s. I will have to create ItemDelegate with specific QlineEdit for each of them. Or engineer some class which will recognize where it is used and set different validators. But I would rather just set validator for existing editor in each list widget... Code less - create more...

    1 Reply Last reply
    0
    • G Offline
      G Offline
      gronerth
      wrote on last edited by
      #2

      How are you adding the items to the QListWidget?


      JETG

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        Creating one delegate will be less code than setting the validator each time you need it... I'm sure there are tricks possible to get access to the QLineEdit, but I don't think that that is the way to go. Instead, you should either create a [[Doc:QStyledItemDelegate]] that creates the editor directly, or create a new [[Doc:QItemEditorFactory]] and register the type you wish to override. There is an example on that in the docs.

        1 Reply Last reply
        0
        • G Offline
          G Offline
          Gourmand
          wrote on last edited by
          #4

          bq. How are you adding the items to the QListWidget?

          just addItem()

          bq. Creating one delegate will be less code than setting the validator each time you need it…

          what?? create proper IetmDelegate subclass (with proper methods and signals) and create QLineEdit subclass - this is shorter than just get one pointer (this should be 1-3 lines of code) and then call setValidator() ???

          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