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. Save App with self MenuBar
Forum Updated to NodeBB v4.3 + New Features

Save App with self MenuBar

Scheduled Pinned Locked Moved Solved General and Desktop
8 Posts 4 Posters 748 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.
  • Z Offline
    Z Offline
    Zayle
    wrote on last edited by
    #1

    Hi,
    I've create self menuBar with the button : File, Save, Save As, etc..

    And i would like to save my Python File with the Windows Explorer, but i completely stuck for the rest of the code.

    self.saveAsAction.setText(_translate("MainWindow", "Save To...")) self.saveAsAction.setShortcut(_translate("MainWindow", "Ctrl+Shift+S"))
    self.saveAsAction.triggered.connect(self.saveAs)
    
     def saveAs(self):
    

    If you have any idea that could unblock me, i'll take it !

    Thanks

    1 Reply Last reply
    0
    • VRoninV Offline
      VRoninV Offline
      VRonin
      wrote on last edited by
      #2

      You probably want to just use https://doc.qt.io/qt-5/qfiledialog.html#getSaveFileName

      "La mort n'est rien, mais vivre vaincu et sans gloire, c'est mourir tous les jours"
      ~Napoleon Bonaparte

      On a crusade to banish setIndexWidget() from the holy land of Qt

      1 Reply Last reply
      1
      • Z Offline
        Z Offline
        Zayle
        wrote on last edited by
        #3

        Hi, and thanks for your answer.
        I continue with the documentation of Qt, but i'm stuck again :

        saveAction = QtGui.QAction("&Save File", self)
                self.saveAction.setText(_translate("MainWindow", "Save To"))
                self.saveAction.setShortcut(_translate("MainWindow", "Ctrl+S"))
                self.saveAction.setStatusTip('Save File')
                self.saveAction.triggered.connect(self.file_save)
        
                self.mainMenu = self.menubar()
                self.fileMenu.addAction(saveAction)
        
            def file_save(self):
                name = QtGui.QFileDialog.getSaveFileName(self, 'Save File')
                file = open(name, 'w')
                text = self.textEdit.toPlainText()
                file.write(text)
                file.close()
        

        I've an error in this line :

        saveAction = QtGui.QAction("&Save File", self)
        

        AttributeError: module 'PyQt5.QtGui' has no attribute 'QAction'

        I don't know how to solve it

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Because QAction is part of the widgets module.

          You have that information in the small table at the top of the documentation.

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

          Z 1 Reply Last reply
          2
          • SGaistS SGaist

            Hi,

            Because QAction is part of the widgets module.

            You have that information in the small table at the top of the documentation.

            Z Offline
            Z Offline
            Zayle
            wrote on last edited by
            #5

            @SGaist Hi, if i understand, this line :

            from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog, QTextEdit, QAction
            

            is enough ?

            JonBJ SGaistS 2 Replies Last reply
            0
            • Z Zayle

              @SGaist Hi, if i understand, this line :

              from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog, QTextEdit, QAction
              

              is enough ?

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

              @Zayle
              Should be! Give it a go?

              1 Reply Last reply
              1
              • Z Zayle

                @SGaist Hi, if i understand, this line :

                from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog, QTextEdit, QAction
                

                is enough ?

                SGaistS Offline
                SGaistS Offline
                SGaist
                Lifetime Qt Champion
                wrote on last edited by
                #7

                @Zayle said in Save App with self MenuBar:

                @SGaist Hi, if i understand, this line :

                from PyQt5.QtWidgets import QApplication, QWidget, QInputDialog, QLineEdit, QFileDialog, QTextEdit, QAction
                

                is enough ?

                If your remove the QtGui. where you use QAction.

                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
                1
                • Z Offline
                  Z Offline
                  Zayle
                  wrote on last edited by
                  #8

                  Ok, i think, understood !
                  Thanks for your help

                  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