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. Programmatically set editable/active QLineEdit (like when user double click on it)

Programmatically set editable/active QLineEdit (like when user double click on it)

Scheduled Pinned Locked Moved Unsolved General and Desktop
15 Posts 5 Posters 2.4k 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #2

    @Please_Help_me_D said in Programmatically set editable/active QLineEdit (like when user double click on it):

    imply calling lineEdit->selectAll() doesn't work.

    It does work.
    Setting the focus can be done with QWidget::setFocus()

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    Please_Help_me_DP 1 Reply Last reply
    5
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #3

      Hi,

      Why not use a validator so your users cannot enter invalid values ?

      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
      3
      • Christian EhrlicherC Christian Ehrlicher

        @Please_Help_me_D said in Programmatically set editable/active QLineEdit (like when user double click on it):

        imply calling lineEdit->selectAll() doesn't work.

        It does work.
        Setting the focus can be done with QWidget::setFocus()

        Please_Help_me_DP Offline
        Please_Help_me_DP Offline
        Please_Help_me_D
        wrote on last edited by
        #4

        @Christian-Ehrlicher I completely forgot to notice that my QLineEdit is a delegate. So to edit something in it I need firstly double-click on it.
        In this way setFocus and selectAll doesn't work as I expect.

        @SGaist I use validator but after user finishes editing I need to additionally check if the full file name is available and unique (filename is a string from lineEdit).

        mrjjM 1 Reply Last reply
        0
        • Please_Help_me_DP Please_Help_me_D

          @Christian-Ehrlicher I completely forgot to notice that my QLineEdit is a delegate. So to edit something in it I need firstly double-click on it.
          In this way setFocus and selectAll doesn't work as I expect.

          @SGaist I use validator but after user finishes editing I need to additionally check if the full file name is available and unique (filename is a string from lineEdit).

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #5

          @Please_Help_me_D
          Hi
          The view can do it.
          https://doc.qt.io/qt-5/qabstractitemview.html#edit

          Please_Help_me_DP 1 Reply Last reply
          1
          • mrjjM mrjj

            @Please_Help_me_D
            Hi
            The view can do it.
            https://doc.qt.io/qt-5/qabstractitemview.html#edit

            Please_Help_me_DP Offline
            Please_Help_me_DP Offline
            Please_Help_me_D
            wrote on last edited by
            #6

            @mrjj thank you
            is it possible to get view from my delegate inherited from QStyledItemDelegate?

            Christian EhrlicherC 1 Reply Last reply
            0
            • Please_Help_me_DP Please_Help_me_D

              @mrjj thank you
              is it possible to get view from my delegate inherited from QStyledItemDelegate?

              Christian EhrlicherC Offline
              Christian EhrlicherC Offline
              Christian Ehrlicher
              Lifetime Qt Champion
              wrote on last edited by
              #7

              @Please_Help_me_D said in Programmatically set editable/active QLineEdit (like when user double click on it):

              is it possible to get view from my delegate inherited from QStyledItemDelegate?

              Why do you need it? Add a validator as @SGaist suggested and you're fine. Or overwrite QStyledItemDelegate::setModelData() and do your checks there.

              Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
              Visit the Qt Academy at https://academy.qt.io/catalog

              Please_Help_me_DP 1 Reply Last reply
              0
              • Christian EhrlicherC Christian Ehrlicher

                @Please_Help_me_D said in Programmatically set editable/active QLineEdit (like when user double click on it):

                is it possible to get view from my delegate inherited from QStyledItemDelegate?

                Why do you need it? Add a validator as @SGaist suggested and you're fine. Or overwrite QStyledItemDelegate::setModelData() and do your checks there.

                Please_Help_me_DP Offline
                Please_Help_me_DP Offline
                Please_Help_me_D
                wrote on last edited by
                #8

                @Christian-Ehrlicher I think validator can't help in this case.
                What I'm doing:
                I have a QLineEdit where user writes name of a file. Well file name can't have some symbols like ?<>/* etc. So I set QRegularExpressionValidator to check symbols.
                Besides there are already files in the folder that have their names. After user finishes editing I must check whether new filename is unique or not. If not then I want that QLineEdit stays active and show tooltip like FileName is not unique.

                Do I need to add all the file names in the folder to the regular expression and set it to validator?

                1 Reply Last reply
                0
                • Christian EhrlicherC Offline
                  Christian EhrlicherC Offline
                  Christian Ehrlicher
                  Lifetime Qt Champion
                  wrote on last edited by
                  #9

                  QLineEdit has some signals which are emitted when the content changes.

                  Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                  Visit the Qt Academy at https://academy.qt.io/catalog

                  1 Reply Last reply
                  0
                  • Please_Help_me_DP Offline
                    Please_Help_me_DP Offline
                    Please_Help_me_D
                    wrote on last edited by
                    #10

                    Can't understand how to perform the idea I described above.
                    The problem was that QStyledItemDelegate::setModelData is invoked before QLineEdit editing finished. I checked that with QAbstractItemView::isPersistentEditorOpen(const QModelIndex &index) const. Thus at the moment when I need to open lineEdit for editing it is already opened but soon will be closed :)
                    That means that QAbstractItemView::openPersistentEditor(const QModelIndex &index) won't help.

                    And QAbstractItemView I get from parent of my model wich is available from QStyledItemDelegate

                    Now I solved my problem in the following way:
                    beside Validator I also added completer with file-name list that are in the folder. So when user fills lineEditor he can see what file-names already in the folder. I hope that is enough for now

                    Christian EhrlicherC JonBJ 2 Replies Last reply
                    1
                    • SGaistS Offline
                      SGaistS Offline
                      SGaist
                      Lifetime Qt Champion
                      wrote on last edited by
                      #11

                      You need your users to enter the path of an existing file ?

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

                      Please_Help_me_DP 1 Reply Last reply
                      0
                      • Please_Help_me_DP Please_Help_me_D

                        Can't understand how to perform the idea I described above.
                        The problem was that QStyledItemDelegate::setModelData is invoked before QLineEdit editing finished. I checked that with QAbstractItemView::isPersistentEditorOpen(const QModelIndex &index) const. Thus at the moment when I need to open lineEdit for editing it is already opened but soon will be closed :)
                        That means that QAbstractItemView::openPersistentEditor(const QModelIndex &index) won't help.

                        And QAbstractItemView I get from parent of my model wich is available from QStyledItemDelegate

                        Now I solved my problem in the following way:
                        beside Validator I also added completer with file-name list that are in the folder. So when user fills lineEditor he can see what file-names already in the folder. I hope that is enough for now

                        Christian EhrlicherC Offline
                        Christian EhrlicherC Offline
                        Christian Ehrlicher
                        Lifetime Qt Champion
                        wrote on last edited by
                        #12

                        @Please_Help_me_D said in Programmatically set editable/active QLineEdit (like when user double click on it):

                        Can't understand how to perform the idea I described above.

                        See QLineEdit::textChanged()

                        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                        Visit the Qt Academy at https://academy.qt.io/catalog

                        1 Reply Last reply
                        0
                        • Please_Help_me_DP Please_Help_me_D

                          Can't understand how to perform the idea I described above.
                          The problem was that QStyledItemDelegate::setModelData is invoked before QLineEdit editing finished. I checked that with QAbstractItemView::isPersistentEditorOpen(const QModelIndex &index) const. Thus at the moment when I need to open lineEdit for editing it is already opened but soon will be closed :)
                          That means that QAbstractItemView::openPersistentEditor(const QModelIndex &index) won't help.

                          And QAbstractItemView I get from parent of my model wich is available from QStyledItemDelegate

                          Now I solved my problem in the following way:
                          beside Validator I also added completer with file-name list that are in the folder. So when user fills lineEditor he can see what file-names already in the folder. I hope that is enough for now

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

                          @Please_Help_me_D
                          Using the QFileDialog to get a filename from the user for either reading from a writing to (whichever of those you want) is an awful lot easier than displaying existing filenames or writing validators if it can suit your situation?

                          1 Reply Last reply
                          0
                          • SGaistS SGaist

                            You need your users to enter the path of an existing file ?

                            Please_Help_me_DP Offline
                            Please_Help_me_DP Offline
                            Please_Help_me_D
                            wrote on last edited by Please_Help_me_D
                            #14

                            @SGaist here is the picture. I have hdf5 container somewhere on the disk (say D:\MyProject\DATA\raw_le.h5). This container contains many datasets that should have unique names. And from this point of view we can look at this like we have a folder raw_le.h5 and files in this folder that should have unique names. When I edit itemData in my proxy model I actually change the name of a file in the raw_le.h5 folder.
                            Ok with validator I can check if there is no restricted symbols in file-name but I also need to check if final itemData (item name/file name) is unique.
                            I wanted that when user finishes editing delegated lineEdit and the final name is not unique I wanted that the lineEdit stays active and a toolTip appears with message Filename is not valid! and user continues to correct the filename without reDOubleClick on item.
                            d8d64de0-5acb-4418-b923-9c7ed0c21910-image.png
                            @Christian-Ehrlicher probably you are right. Probably I need to check uniqueness of a file when typing and not when editingFinished.

                            JonBJ 1 Reply Last reply
                            0
                            • Please_Help_me_DP Please_Help_me_D

                              @SGaist here is the picture. I have hdf5 container somewhere on the disk (say D:\MyProject\DATA\raw_le.h5). This container contains many datasets that should have unique names. And from this point of view we can look at this like we have a folder raw_le.h5 and files in this folder that should have unique names. When I edit itemData in my proxy model I actually change the name of a file in the raw_le.h5 folder.
                              Ok with validator I can check if there is no restricted symbols in file-name but I also need to check if final itemData (item name/file name) is unique.
                              I wanted that when user finishes editing delegated lineEdit and the final name is not unique I wanted that the lineEdit stays active and a toolTip appears with message Filename is not valid! and user continues to correct the filename without reDOubleClick on item.
                              d8d64de0-5acb-4418-b923-9c7ed0c21910-image.png
                              @Christian-Ehrlicher probably you are right. Probably I need to check uniqueness of a file when typing and not when editingFinished.

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

                              @Please_Help_me_D said in Programmatically set editable/active QLineEdit (like when user double click on it):

                              @Christian-Ehrlicher probably you are right. Probably I need to check uniqueness of a file when typing and not when editingFinished.

                              Yes, if you want to stay in editing mode, instead of exiting it and then having to restart, your validator should check for a unique file as the user types and reject the input if not. Then the editingFinished() signal will not be emitted on a duplicate filename.

                              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