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. How to create a custom Save File Window
Forum Updated to NodeBB v4.3 + New Features

How to create a custom Save File Window

Scheduled Pinned Locked Moved Unsolved General and Desktop
9 Posts 4 Posters 1.1k 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
    aftalib
    wrote on 6 Jun 2021, 12:38 last edited by
    #1

    Hello, im working on a app that requires saving files and i want to create a window that takes cares itself of saving the file i want.

    I'll explain : i am using the getSaveFileName() method in order to save my file, but this method opens a Desktop window, and this is what i dont want. i would like that my window takes cares itself of selecting the path, and the name of the file, and then when i click on "save" there is no desktop window popping up.

    Does anyone knows a way to do this ?

    J 1 Reply Last reply 6 Jun 2021, 13:04
    0
    • A aftalib
      6 Jun 2021, 12:38

      Hello, im working on a app that requires saving files and i want to create a window that takes cares itself of saving the file i want.

      I'll explain : i am using the getSaveFileName() method in order to save my file, but this method opens a Desktop window, and this is what i dont want. i would like that my window takes cares itself of selecting the path, and the name of the file, and then when i click on "save" there is no desktop window popping up.

      Does anyone knows a way to do this ?

      J Offline
      J Offline
      JonB
      wrote on 6 Jun 2021, 13:04 last edited by JonB 6 Jun 2021, 13:05
      #2

      @aftalib
      So if you really do not want to use QFileDialog, don't use it! Then it's up to you to write a suitable replacement yourself. But that means that if, say, you still want the user to browse to a directory for saving you must construct something suitable. If all you want is the user to type a full path, or type a directory path plus a filename, you could use your own QLineEdits.

      QFileDialog does not do any opening or saving. It only allows the user to pick a path and returns that. It's up to your caller what it chooses to do with that.

      What you might want instead is your own dialog/window with whatever of your own it, plus a QLineEdit and an associated button. Clicking the button invokes the QFileDialog. Selecting a file there and pressing OK copies the path back into your invoking dialog. Your invoking dialog has all the code for actually doing the save or load.

      A 1 Reply Last reply 7 Jun 2021, 07:06
      2
      • M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 6 Jun 2021, 13:15 last edited by mrjj 6 Jun 2021, 13:20
        #3

        Hi
        do note that with QFileDialog
        you can set up both filename and path before showing it to the user.
        Then the user can just press save to save in the default location the app told it.

        Also, many users including my self do not like custom save dialogs.
        its just annoying as they often have missing features, cant browse shares or is limited in many other ways.

        but if you actually mean just to allow the app to save to the same location and the user don't even have to specify the filename
        then it's another story.

        A 1 Reply Last reply 7 Jun 2021, 07:08
        2
        • J JonB
          6 Jun 2021, 13:04

          @aftalib
          So if you really do not want to use QFileDialog, don't use it! Then it's up to you to write a suitable replacement yourself. But that means that if, say, you still want the user to browse to a directory for saving you must construct something suitable. If all you want is the user to type a full path, or type a directory path plus a filename, you could use your own QLineEdits.

          QFileDialog does not do any opening or saving. It only allows the user to pick a path and returns that. It's up to your caller what it chooses to do with that.

          What you might want instead is your own dialog/window with whatever of your own it, plus a QLineEdit and an associated button. Clicking the button invokes the QFileDialog. Selecting a file there and pressing OK copies the path back into your invoking dialog. Your invoking dialog has all the code for actually doing the save or load.

          A Offline
          A Offline
          aftalib
          wrote on 7 Jun 2021, 07:06 last edited by
          #4

          @JonB the thing is, i would like do to something like this : 689b46ff-0beb-4a53-a597-3970a855f8fe-image.png

          (this window is not made using Qt)

          so as you can see, the user chooses a directory among those available (thomson, etc..), types the name of its file, clicks on save and that's it.

          I think that im seeing what you're explaining but i dont get the part with QLineEdit, i dont think i ever worked with those. Do you think you would have an example of code using it with a similar case ?

          Thank you

          1 Reply Last reply
          1
          • M mrjj
            6 Jun 2021, 13:15

            Hi
            do note that with QFileDialog
            you can set up both filename and path before showing it to the user.
            Then the user can just press save to save in the default location the app told it.

            Also, many users including my self do not like custom save dialogs.
            its just annoying as they often have missing features, cant browse shares or is limited in many other ways.

            but if you actually mean just to allow the app to save to the same location and the user don't even have to specify the filename
            then it's another story.

            A Offline
            A Offline
            aftalib
            wrote on 7 Jun 2021, 07:08 last edited by
            #5

            @mrjj Yes i know that i can choose the filename and the path with QFileDialog but i really need a window for this..

            I personnaly would prefer the classic window but i'm not doing this for myself, someone told me specifically to do it like this ahah

            J 1 Reply Last reply 7 Jun 2021, 07:09
            0
            • A aftalib
              7 Jun 2021, 07:08

              @mrjj Yes i know that i can choose the filename and the path with QFileDialog but i really need a window for this..

              I personnaly would prefer the classic window but i'm not doing this for myself, someone told me specifically to do it like this ahah

              J Offline
              J Offline
              J.Hilk
              Moderators
              wrote on 7 Jun 2021, 07:09 last edited by
              #6

              @aftalib Qt has a Dir (Tree)View example

              https://doc.qt.io/qt-5/qtwidgets-itemviews-dirview-example.html

              that should give you a really good starting point to implement/create what you want


              Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


              Q: What's that?
              A: It's blue light.
              Q: What does it do?
              A: It turns blue.

              A 1 Reply Last reply 7 Jun 2021, 08:40
              3
              • J J.Hilk
                7 Jun 2021, 07:09

                @aftalib Qt has a Dir (Tree)View example

                https://doc.qt.io/qt-5/qtwidgets-itemviews-dirview-example.html

                that should give you a really good starting point to implement/create what you want

                A Offline
                A Offline
                aftalib
                wrote on 7 Jun 2021, 08:40 last edited by
                #7

                @J-Hilk oh yeah thanks this is exactly what i'm looking for.

                However i am trying to get DirView into a QGraphicsScene, like this : ```
                QGraphicsScene* scene = new QGraphicsScene(QRect(100, 100, 400, 200));

                  treeSave->setHeaderHidden(true);
                  QFileSystemModel model;
                  model.setRootPath(QDir::currentPath());
                  treeSave->setModel(&model);
                
                
                  // Demonstrating look and feel features
                  treeSave->setAnimated(false);
                  treeSave->setIndentation(20);
                  treeSave->setSortingEnabled(true);
                  const QSize availableSize = treeSave->screen()->availableGeometry().size();
                  treeSave->resize(availableSize / 2);
                  treeSave->setColumnWidth(0, treeSave->width() / 3);
                
                
                
                  treeSave->setWindowTitle(QObject::tr("Dir View"));
                

                treeSave->setGeometry(100,100,400,200);

                QVBoxLayout *lay = new QVBoxLayout;
                lay->addWidget(treeSave);
                view = new QGraphicsView();
                view->setLayout(lay);
                
                view->setScene(scene);
                view->setWindowTitle("Save your file");
                view->setGeometry(QRect(520, 520, 400, 200));
                view->setContentsMargins(0,0,0,0);
                view->show();
                
                
                but this just gives me a blank window..
                J 1 Reply Last reply 7 Jun 2021, 08:46
                0
                • A aftalib
                  7 Jun 2021, 08:40

                  @J-Hilk oh yeah thanks this is exactly what i'm looking for.

                  However i am trying to get DirView into a QGraphicsScene, like this : ```
                  QGraphicsScene* scene = new QGraphicsScene(QRect(100, 100, 400, 200));

                    treeSave->setHeaderHidden(true);
                    QFileSystemModel model;
                    model.setRootPath(QDir::currentPath());
                    treeSave->setModel(&model);
                  
                  
                    // Demonstrating look and feel features
                    treeSave->setAnimated(false);
                    treeSave->setIndentation(20);
                    treeSave->setSortingEnabled(true);
                    const QSize availableSize = treeSave->screen()->availableGeometry().size();
                    treeSave->resize(availableSize / 2);
                    treeSave->setColumnWidth(0, treeSave->width() / 3);
                  
                  
                  
                    treeSave->setWindowTitle(QObject::tr("Dir View"));
                  

                  treeSave->setGeometry(100,100,400,200);

                  QVBoxLayout *lay = new QVBoxLayout;
                  lay->addWidget(treeSave);
                  view = new QGraphicsView();
                  view->setLayout(lay);
                  
                  view->setScene(scene);
                  view->setWindowTitle("Save your file");
                  view->setGeometry(QRect(520, 520, 400, 200));
                  view->setContentsMargins(0,0,0,0);
                  view->show();
                  
                  
                  but this just gives me a blank window..
                  J Offline
                  J Offline
                  J.Hilk
                  Moderators
                  wrote on 7 Jun 2021, 08:46 last edited by
                  #8

                  @aftalib said in How to create a custom Save File Window:

                  QGraphicsView

                  I have no experience myself with this. Can you even add a simple QWidget to a QGraphicsScene ? I thought it has to be derived from QGraphicsItem

                  If you can not simply add QWdigets to a Scene then your approach will not work.


                  Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                  Q: What's that?
                  A: It's blue light.
                  Q: What does it do?
                  A: It turns blue.

                  M 1 Reply Last reply 7 Jun 2021, 09:19
                  0
                  • J J.Hilk
                    7 Jun 2021, 08:46

                    @aftalib said in How to create a custom Save File Window:

                    QGraphicsView

                    I have no experience myself with this. Can you even add a simple QWidget to a QGraphicsScene ? I thought it has to be derived from QGraphicsItem

                    If you can not simply add QWdigets to a Scene then your approach will not work.

                    M Offline
                    M Offline
                    mrjj
                    Lifetime Qt Champion
                    wrote on 7 Jun 2021, 09:19 last edited by
                    #9

                    @J-Hilk said in How to create a custom Save File Window:

                    QGraphicsScene

                    Hi
                    you do it via
                    QGraphicsProxyWidget
                    https://doc.qt.io/qt-5/qgraphicsscene.html#addWidget

                    addWidgets constructs one for you.

                    @aftalib

                    you have QFileSystemModel model; as a local variable

                    so when i see
                    treeSave->setModel(&model);

                    i fear it will run out of scope.

                    1 Reply Last reply
                    3

                    1/9

                    6 Jun 2021, 12:38

                    • Login

                    • Login or register to search.
                    1 out of 9
                    • First post
                      1/9
                      Last post
                    0
                    • Categories
                    • Recent
                    • Tags
                    • Popular
                    • Users
                    • Groups
                    • Search
                    • Get Qt Extensions
                    • Unsolved