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. Qt File selector?
Forum Updated to NodeBB v4.3 + New Features

Qt File selector?

Scheduled Pinned Locked Moved Solved General and Desktop
9 Posts 4 Posters 679 Views 2 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.
  • SPlattenS Offline
    SPlattenS Offline
    SPlatten
    wrote on last edited by SPlatten
    #1

    Is there a GUI style file selector available in Qt, I've seen QFileSelector, but it isn't derived from QWidget so I'm not sure if its the thing I'm looking for.

    Kind Regards,
    Sy

    Pl45m4P 1 Reply Last reply
    0
    • JonBJ JonB

      @artwaw
      I didn't notice it said QTextEdit instead of QLineEdit :) I'm sure the latter was intended.

      Yours sounds nice. I don't have Qt here, how does the user know to click what to pull up the QFileDialog? "with an icon and no text": does that means something comes up on right-click?

      artwawA Offline
      artwawA Offline
      artwaw
      wrote on last edited by artwaw
      #8

      @JonB Here, this is taken from one of my projects.
      Assume you have UI (in my case it is QDialog for options setting), where QLineEdit named dbFileEdit is present. This code is in my ctor:

          QAction *findFile = new QAction(QIcon("/gfx/file-2.png"),"",this);
          findFile->setToolTip("Browse for file...");
          connect(findFile,&QAction::triggered,this,&optiondlg::selectFile);
          ui->dbFileEdit->addAction(findFile,QLineEdit::TrailingPosition);
      

      I could go with a lambda instead of the slot but I do some other things there too.

      So the idea is that the icon and tooltips are meaningful giving a hint to the user. In my case it looks like this:
      Screenshot 2021-05-09 at 13.29.48.png

      I also use this kind of thing when offering users an option to switch between masked/clear text echo with passwords.

      EDIT:
      For right click you'd need to go w the custom context menu for QLineEdit, this QAction reacts to the regular left click, offering standard QAction features like statusTip and toolTip - I find it less of a hassle than context menus. And it saves ton of space in widget rich UIs too.

      EDIT2: typos.

      For more information please re-read.

      Kind Regards,
      Artur

      SPlattenS 1 Reply Last reply
      4
      • SPlattenS SPlatten

        Is there a GUI style file selector available in Qt, I've seen QFileSelector, but it isn't derived from QWidget so I'm not sure if its the thing I'm looking for.

        Pl45m4P Offline
        Pl45m4P Offline
        Pl45m4
        wrote on last edited by
        #2

        @SPlatten

        QFileDialog

        • https://doc.qt.io/qt-5/qfiledialog.html#details

        If debugging is the process of removing software bugs, then programming must be the process of putting them in.

        ~E. W. Dijkstra

        SPlattenS 1 Reply Last reply
        1
        • Pl45m4P Pl45m4

          @SPlatten

          QFileDialog

          • https://doc.qt.io/qt-5/qfiledialog.html#details
          SPlattenS Offline
          SPlattenS Offline
          SPlatten
          wrote on last edited by SPlatten
          #3

          @Pl45m4, What I really need is a one liner QTextEdit box with a ... QPushButton to the right of the text box which then invokes an instance of QFileDialog.

          If this isn't available already then I think I will have to create a custom widget to do it.

          Kind Regards,
          Sy

          JonBJ artwawA Pl45m4P 3 Replies Last reply
          0
          • SPlattenS SPlatten

            @Pl45m4, What I really need is a one liner QTextEdit box with a ... QPushButton to the right of the text box which then invokes an instance of QFileDialog.

            If this isn't available already then I think I will have to create a custom widget to do it.

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

            @SPlatten
            You have to roll exactly that yourself. Qt doesn't supply it, dunno if someone has posted one somewhere.

            1 Reply Last reply
            1
            • SPlattenS SPlatten

              @Pl45m4, What I really need is a one liner QTextEdit box with a ... QPushButton to the right of the text box which then invokes an instance of QFileDialog.

              If this isn't available already then I think I will have to create a custom widget to do it.

              artwawA Offline
              artwawA Offline
              artwaw
              wrote on last edited by
              #5

              @SPlatten you may also add an action to QLineEdit (I am not sure why you want single line QTextEdit) with an icon and no text. Connect the action to the slot or lamda calling QFileDialog. I do that routinely for browse for location UI features. Once you have the action set you just https://doc.qt.io/qt-5/qlineedit.html#addAction

              For more information please re-read.

              Kind Regards,
              Artur

              JonBJ 1 Reply Last reply
              1
              • SPlattenS SPlatten

                @Pl45m4, What I really need is a one liner QTextEdit box with a ... QPushButton to the right of the text box which then invokes an instance of QFileDialog.

                If this isn't available already then I think I will have to create a custom widget to do it.

                Pl45m4P Offline
                Pl45m4P Offline
                Pl45m4
                wrote on last edited by
                #6

                @SPlatten

                You still can do it with QFileDialog. Your button will open the dialog and the returned path is displayed in your TextEdit.


                If debugging is the process of removing software bugs, then programming must be the process of putting them in.

                ~E. W. Dijkstra

                1 Reply Last reply
                0
                • artwawA artwaw

                  @SPlatten you may also add an action to QLineEdit (I am not sure why you want single line QTextEdit) with an icon and no text. Connect the action to the slot or lamda calling QFileDialog. I do that routinely for browse for location UI features. Once you have the action set you just https://doc.qt.io/qt-5/qlineedit.html#addAction

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

                  @artwaw
                  I didn't notice it said QTextEdit instead of QLineEdit :) I'm sure the latter was intended.

                  Yours sounds nice. I don't have Qt here, how does the user know to click what to pull up the QFileDialog? "with an icon and no text": does that means something comes up on right-click?

                  artwawA 1 Reply Last reply
                  1
                  • JonBJ JonB

                    @artwaw
                    I didn't notice it said QTextEdit instead of QLineEdit :) I'm sure the latter was intended.

                    Yours sounds nice. I don't have Qt here, how does the user know to click what to pull up the QFileDialog? "with an icon and no text": does that means something comes up on right-click?

                    artwawA Offline
                    artwawA Offline
                    artwaw
                    wrote on last edited by artwaw
                    #8

                    @JonB Here, this is taken from one of my projects.
                    Assume you have UI (in my case it is QDialog for options setting), where QLineEdit named dbFileEdit is present. This code is in my ctor:

                        QAction *findFile = new QAction(QIcon("/gfx/file-2.png"),"",this);
                        findFile->setToolTip("Browse for file...");
                        connect(findFile,&QAction::triggered,this,&optiondlg::selectFile);
                        ui->dbFileEdit->addAction(findFile,QLineEdit::TrailingPosition);
                    

                    I could go with a lambda instead of the slot but I do some other things there too.

                    So the idea is that the icon and tooltips are meaningful giving a hint to the user. In my case it looks like this:
                    Screenshot 2021-05-09 at 13.29.48.png

                    I also use this kind of thing when offering users an option to switch between masked/clear text echo with passwords.

                    EDIT:
                    For right click you'd need to go w the custom context menu for QLineEdit, this QAction reacts to the regular left click, offering standard QAction features like statusTip and toolTip - I find it less of a hassle than context menus. And it saves ton of space in widget rich UIs too.

                    EDIT2: typos.

                    For more information please re-read.

                    Kind Regards,
                    Artur

                    SPlattenS 1 Reply Last reply
                    4
                    • artwawA artwaw

                      @JonB Here, this is taken from one of my projects.
                      Assume you have UI (in my case it is QDialog for options setting), where QLineEdit named dbFileEdit is present. This code is in my ctor:

                          QAction *findFile = new QAction(QIcon("/gfx/file-2.png"),"",this);
                          findFile->setToolTip("Browse for file...");
                          connect(findFile,&QAction::triggered,this,&optiondlg::selectFile);
                          ui->dbFileEdit->addAction(findFile,QLineEdit::TrailingPosition);
                      

                      I could go with a lambda instead of the slot but I do some other things there too.

                      So the idea is that the icon and tooltips are meaningful giving a hint to the user. In my case it looks like this:
                      Screenshot 2021-05-09 at 13.29.48.png

                      I also use this kind of thing when offering users an option to switch between masked/clear text echo with passwords.

                      EDIT:
                      For right click you'd need to go w the custom context menu for QLineEdit, this QAction reacts to the regular left click, offering standard QAction features like statusTip and toolTip - I find it less of a hassle than context menus. And it saves ton of space in widget rich UIs too.

                      EDIT2: typos.

                      SPlattenS Offline
                      SPlattenS Offline
                      SPlatten
                      wrote on last edited by
                      #9

                      @artwaw , Thank you, I've resolved this now.

                      Kind Regards,
                      Sy

                      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