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 can I show QToolBar again, after having closed it?
QtWS25 Last Chance

How can I show QToolBar again, after having closed it?

Scheduled Pinned Locked Moved Solved General and Desktop
7 Posts 2 Posters 745 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.
  • lincolnL Offline
    lincolnL Offline
    lincoln
    wrote on last edited by
    #1

    Good afternoon, my question is how I can show a QToolBar again after having closed it, I happened to right click on my toolbar and it showed me a contextual menu, which I clicked on, and I close the toolbar, but then I couldn't go back to show it, some suggestion to solve this little problem.

    This is the menu that came out before closing the toolbar. The window is not from my application, what happens is, as I mentioned before the toolbar is no longer shown so I had to create a new app, to show them the option that I got. I hope you can help me, thanks in advance.

    a5473fec-87a9-430d-8b77-87243f1b8b03-image.png

    Solitary wolf

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

      @lincoln said in How can I show QToolBar again, after having closed it?:

      If I already tried that and it does not work, since when I close, and reload the app again the toolbar is shown hidden, since I mentioned earlier that I am using saveState () of the QMainWindow to save the state of my application, here the code:

      Where and when did you try that ?
      If you set that in the constructor before calling readSettings, then it's going to be useless.
      The other issue that might arise is that in the constructor, the widget does not have any notion of visibility since does not yet "physically" exists. To make your life simpler in the current situation just nuke the settings file so can start from clean state. In any case, you should either add the toggle action as I suggested before or at least add an action that allows to reset the state of your widgets to a sensible default.

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

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

        Hi,

        You can add the QToolBar::toggleViewAction to a menu of your main window.

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

        lincolnL 1 Reply Last reply
        0
        • SGaistS SGaist

          Hi,

          You can add the QToolBar::toggleViewAction to a menu of your main window.

          lincolnL Offline
          lincolnL Offline
          lincoln
          wrote on last edited by
          #3

          @SGaist
          I just discovered that my problem is that I have a writeSettings () function, which saves the states of my app, and another readSettings (), to load the configurations, so I am using saveState () from the QMainWindow, that is what this preventing my toolbar from showing after reopening my app; Then I rectify my question, how do I restore the toolbar, from my readSettings () function. I mean so that it is shown when loading the app.

          Solitary wolf

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

            Call setVisible(true) on your toolbar.

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

            lincolnL 1 Reply Last reply
            0
            • SGaistS SGaist

              Call setVisible(true) on your toolbar.

              lincolnL Offline
              lincolnL Offline
              lincoln
              wrote on last edited by lincoln
              #5

              @SGaist
              If I already tried that and it does not work, since when I close, and reload the app again the toolbar is shown hidden, since I mentioned earlier that I am using saveState () of the QMainWindow to save the state of my application, here the code:

              #ifndef FRMPRINCIPAL_H
              #define FRMPRINCIPAL_H
              
              #include <QMainWindow>
              #include <QPaintEngine>
              #include <QSettings>
              
              #include "qeasysettings.hpp"
              namespace Ui {
                class FrmPrincipal;
              }
              
              class FrmPrincipal : public QMainWindow
              {
                Q_OBJECT
              
              public:
                explicit FrmPrincipal(QWidget *parent = nullptr);
                ~FrmPrincipal();
                void readSettings();
                void writeSettings();
               
              private:
                Ui::FrmPrincipal *ui;
              
                 // QPaintDevice interface
              public:
                virtual QPaintEngine *paintEngine() const override;
              
                // QWidget interface
              protected:
                virtual void closeEvent(QCloseEvent *event) override;
              
              };
              
              #endif // FRMPRINCIPAL_H
              
              
              #include "frmprincipal.h"
              #include "ui_frmprincipal.h"
              
              FrmPrincipal::FrmPrincipal(QWidget *parent) :
                QMainWindow(parent),  ui(new Ui::FrmPrincipal)
              {
                ui->setupUi(this);
                readSettings();
              }
              void FrmPrincipal::readSettings()
              {
                QEasySettings::init(QEasySettings::Format::regFormat,qApp->organizationName());
                restoreGeometry(QEasySettings::readSettings("MainWindow","geometry").toByteArray());
                restoreState(QEasySettings::readSettings("MainWindow","windowState").toByteArray());
                ui->splitter->restoreState(QEasySettings::readSettings("MainWindow","splitterState").toByteArray());
              
               }
              
              void FrmPrincipal::writeSettings()
              {
                QEasySettings::writeSettings("MainWindow","geometry",saveGeometry());
                QEasySettings::writeSettings("MainWindow","windowState",saveState());
                QEasySettings::writeSettings("MainWindow","splitterState",ui->splitter->saveState());
              
               }
              QPaintEngine *FrmPrincipal::paintEngine() const
              {
                return QWidget::paintEngine();
              }
              
              void FrmPrincipal::closeEvent(QCloseEvent *event)
              {
                writeSettings();
                QMainWindow::closeEvent(event);
              }
              

              I am using QEasySettings to save my app settings.:
              https://github.com/mguludag/QEasySettings

              Solitary wolf

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

                @lincoln said in How can I show QToolBar again, after having closed it?:

                If I already tried that and it does not work, since when I close, and reload the app again the toolbar is shown hidden, since I mentioned earlier that I am using saveState () of the QMainWindow to save the state of my application, here the code:

                Where and when did you try that ?
                If you set that in the constructor before calling readSettings, then it's going to be useless.
                The other issue that might arise is that in the constructor, the widget does not have any notion of visibility since does not yet "physically" exists. To make your life simpler in the current situation just nuke the settings file so can start from clean state. In any case, you should either add the toggle action as I suggested before or at least add an action that allows to reset the state of your widgets to a sensible default.

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

                lincolnL 1 Reply Last reply
                1
                • SGaistS SGaist

                  @lincoln said in How can I show QToolBar again, after having closed it?:

                  If I already tried that and it does not work, since when I close, and reload the app again the toolbar is shown hidden, since I mentioned earlier that I am using saveState () of the QMainWindow to save the state of my application, here the code:

                  Where and when did you try that ?
                  If you set that in the constructor before calling readSettings, then it's going to be useless.
                  The other issue that might arise is that in the constructor, the widget does not have any notion of visibility since does not yet "physically" exists. To make your life simpler in the current situation just nuke the settings file so can start from clean state. In any case, you should either add the toggle action as I suggested before or at least add an action that allows to reset the state of your widgets to a sensible default.

                  lincolnL Offline
                  lincolnL Offline
                  lincoln
                  wrote on last edited by
                  #7

                  @SGaist
                  Thanks for your answer, add an action like suggest, in a context menu, and with that solve my problem.

                  Solitary wolf

                  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