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 and Restore QToolbar position
QtWS25 Last Chance

Save and Restore QToolbar position

Scheduled Pinned Locked Moved General and Desktop
22 Posts 3 Posters 18.3k 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.
  • ? This user is from outside of this forum
    ? This user is from outside of this forum
    Guest
    wrote on last edited by
    #2

    Just add some member variables to hold the states of your toolbars, when application is terminated serialize their values to a file, when application is ran again read that file and set your toolbars accordingly.

    1 Reply Last reply
    0
    • ? This user is from outside of this forum
      ? This user is from outside of this forum
      Guest
      wrote on last edited by
      #3

      Suppose i have:
      [code]
      class MyClass
      {
      QMainWindow* m_wnd;
      QToolBar* m_toolBar1;
      QToolBar* m_toolBar2;
      QToolBar* m_toolBar3;

      xxx saveState(QToolBar* toolBar) const
      {
      ?
      }

      void restoreState(const xxx&, QToolBar* toolBar)
      {
      ?
      }

      };
      [/code]

      How do i save and restore position of m_toolBar? I tried with m_toolBar->saveState / restoreState and that did not work

      1 Reply Last reply
      0
      • ? This user is from outside of this forum
        ? This user is from outside of this forum
        Guest
        wrote on last edited by
        #4

        First of all, use the code wrapper function when pasting code in the forum. Second - that code does not contain toolbars, only pointers to toolbars, in the constructor of your class you will call methods to create the toolbars, you can set the custom variables that hold your toolbar states - whether a toolbar is visible, whether it is floating, where is it docked and so forth, connect the signals emitted when the toolbars are arranged by the user to slots that again store the state in your custom variables. You can put a method that saves those user variables to a file in the destructor, and in the constructor check if the file exists, and if so, read in the data from it and restore the toolbars the same way the user left them when he quit the application.

        QToolBar has NO save and restore state methods! Unless someone else knows a standard way to do it with the Qt API, you will have to do it yourself in the manner I keep on describing to you.

        1 Reply Last reply
        0
        • ? This user is from outside of this forum
          ? This user is from outside of this forum
          Guest
          wrote on last edited by
          #5

          connect the signals emitted when the toolbars are arranged by the user to slots that again store the state in your custom variables

          Which signals do you mean?

          restore the toolbars the same way
          Which way do you mean?

          It sounds like i should reprogramm the whole QToolbar logic in my code...

          What i need is the following:
          [code]
          ostream << m_toolBar1->position();
          ostream << m_toolBar1->orientation();
          ostream << m_toolBar1->size();
          ...

          m_toolBar1->setPosition(getPosition(istream));
          m_toolBar1->setOrientation(getOrientation(istream));
          m_toolBar1->resize(getSize(istream));
          [/code]

          1 Reply Last reply
          0
          • ? This user is from outside of this forum
            ? This user is from outside of this forum
            Guest
            wrote on last edited by
            #6

            No, you don't have to touch the logic of QToolBar at all. You only need to serialize a few variables that hold information on whether your toolbars are visible, docked or floating, and respectively where are docked or their floating position. When a toolbar is modified it emits a range of signals such as:

            @void visibilityChanged ( bool visible )
            void orientationChanged ( Qt::Orientation orientation )@

            you also have QToolBar member methods such as:

            @bool isAreaAllowed ( Qt::ToolBarArea area ) const
            bool isFloatable () const
            bool isFloating () const
            bool isMovable () const@

            1 Reply Last reply
            0
            • ? This user is from outside of this forum
              ? This user is from outside of this forum
              Guest
              wrote on last edited by
              #7

              [quote author="ddriver" date="1331817648"]... You only need to serialize a few variables that hold information on whether your toolbars are visible, docked or floating, and respectively where are docked or their floating position...
              [/quote]

              I do not need info about visibility or orientation, i just want to know how i can save and restore the position of a QToolbar... Is it possible?

              1 Reply Last reply
              0
              • ? This user is from outside of this forum
                ? This user is from outside of this forum
                Guest
                wrote on last edited by
                #8

                Have you actually read all the stuff I posted? I already told you how, both in short and in detail, and you still ask? It is basic programming so sorry if I am not rushing to write the code for you. QToolBar already has all the methods you need to copy its state into your custom variables and to restore the state from those variables.

                1 Reply Last reply
                0
                • ? This user is from outside of this forum
                  ? This user is from outside of this forum
                  Guest
                  wrote on last edited by
                  #9

                  Please do not extend your posts...
                  [quote author="ddriver" date="1331816587"]QToolBar has NO save and restore state methods! Unless someone else knows a standard way to do it with the Qt API, you will have to do it yourself in the manner I keep on describing to you.[/quote]
                  [quote author="ddriver" date="1331818311"]I already told you how, both in short and in detail, and you still ask?[/quote]
                  So, it is impossible, isn't it?

                  Otherwise, could you show me how to get and restore the position?
                  [code]
                  ostream << m_toolBar1->position();
                  ...
                  m_toolBar1->setPosition(getPosition(istream));
                  [/code]

                  1 Reply Last reply
                  0
                  • ? This user is from outside of this forum
                    ? This user is from outside of this forum
                    Guest
                    wrote on last edited by
                    #10

                    Can't you read English? I already told you HOW to do it, by what type of logic you assume it is impossible? Judging from your responses it seems like you need to work on your C++ and basic programming skills before you rush into building applications.

                    QToolBar inherits a QPoint returning member function called pos from QWidget that holds the position of the toolbar in its parent widget.

                    Start off by a bool isToolBar1Created, set it to false, when your user creates the toolbar, then set it to true.

                    Then have another one, bool isToolBar1Docked, when the user docks the toobar, set it to true, when the user detaches the toolbar to be floating, set it to false.

                    Then have a third variable that depending on whether the toolbar is floating or not, contains either its position or the location it is docked at.

                    When the user quits the application, write the three variables to a file. When the application is ran again, read in the file, if the first variable is false, then you don't create a toolbar, if it is true, then you create the toolbar, when you create it, check the second variable, if it is true then read the third for the dock location and dock the toolbar in that location. If it is false, set the toobar to floating and move it to the position stored in the third variable.

                    100% possible as you see.

                    1 Reply Last reply
                    0
                    • ? This user is from outside of this forum
                      ? This user is from outside of this forum
                      Guest
                      wrote on last edited by
                      #11

                      Please stop editing your posts.

                      [quote author="ddriver" date="1331819488"]I already told you HOW to do it, by what type of logic you assume it is impossible?[/quote]
                      You said everything, but not a word about a position. I need a postion, a relative position, a floation position, not visibility, not if its dockable or not, not orientation. A position. Just a position.

                      1 Reply Last reply
                      0
                      • ? This user is from outside of this forum
                        ? This user is from outside of this forum
                        Guest
                        wrote on last edited by
                        #12

                        [quote author="ddriver" date="1331819488"]
                        QToolBar inherits a QPoint returning member function called pos from QWidget that holds the position of the toolbar in its parent widget.[/quote]

                        Also, learn how to use the PLENTIFUL and DETAILED Qt documentation.

                        bq. pos : QPoint
                        This property holds the position of the widget within its parent widget.

                        You also have:

                        @void move ( const QPoint & )@

                        which, in case you cannot figure out, moves the widget to the QPoint location.

                        http://qt-project.org/doc/qt-4.8/qtoolbar-members.html
                        http://qt-project.org/doc/qt-4.8/qwidget.html#pos-prop

                        As you probably (don't) see, it is not only ENTIRELY possible, but QUITE EASY...

                        I also suggest you remove that foolish "[Impossible in Qt!]" qualifier from your thread and rethink your strategy - I really don't think you will go far into programming if you expect others to do the thinking and reading for you.

                        1 Reply Last reply
                        0
                        • ? This user is from outside of this forum
                          ? This user is from outside of this forum
                          Guest
                          wrote on last edited by
                          #13

                          It is cool how you change your posts in the past from the future...

                          1 Reply Last reply
                          0
                          • ? This user is from outside of this forum
                            ? This user is from outside of this forum
                            Guest
                            wrote on last edited by
                            #14

                            Certainly not as cool as being a lazy ungrateful jackass to people who waste their time to help you. Good luck, I am done with you!

                            1 Reply Last reply
                            0
                            • ? This user is from outside of this forum
                              ? This user is from outside of this forum
                              Guest
                              wrote on last edited by
                              #15

                              [quote author="ddriver" date="1331829830"]Certainly not as cool as being a lazy ungrateful jackass to people who waste their time to help you. Good luck, I am done with you![/quote]
                              I hope you will not come back, dude.

                              1 Reply Last reply
                              0
                              • T Offline
                                T Offline
                                tobias.hunger
                                wrote on last edited by
                                #16

                                ddriver: There is no need to call people names here. Just move on to another thread if somebody annoys you.

                                1 Reply Last reply
                                0
                                • ? This user is from outside of this forum
                                  ? This user is from outside of this forum
                                  Guest
                                  wrote on last edited by
                                  #17

                                  [quote author="ddriver" date="1331819988"][quote author="ddriver" date="1331819488"]
                                  QToolBar inherits a QPoint returning member function called pos from QWidget that holds the position of the toolbar in its parent widget.[/quote]
                                  This property holds the position of the widget within its parent widget.
                                  You also have:
                                  @void move ( const QPoint & )@
                                  which, in case you cannot figure out, moves the widget to the QPoint location.
                                  [/quote]

                                  It just does not work with QToolBar, dude.
                                  Try it youself:

                                  [code]
                                  QPoint posa(m_toolBar1->pos());
                                  m_toolBar1->move(pos.x()+10, pos.y());
                                  [/code]

                                  The toolbar stays where it was.

                                  1 Reply Last reply
                                  0
                                  • ? This user is from outside of this forum
                                    ? This user is from outside of this forum
                                    Guest
                                    wrote on last edited by
                                    #18

                                    Both pos() and move() work for me perfectly well, when the toolbar is docked it returns and moves to coordinates, relative to the application window, when floating, it is relative to the active display, so the problem is all in your "TV", dude!

                                    @Tobias Hunger - it wasn't a name, but a definition, it is offensive only when it is degrading, if it is justified and objective - I don't think there is something wrong with calling things what they are :)

                                    1 Reply Last reply
                                    0
                                    • . Offline
                                      . Offline
                                      .ddriver
                                      wrote on last edited by
                                      #19

                                      O, really?

                                      [code]
                                      #include <QtGui>

                                      int main(int argc, char argv[])
                                      {
                                      QApplication a(argc, argv);
                                      QMainWindow wnd1;
                                      QMainWindow
                                      wnd(&wnd1);
                                      QToolBar* m_toolBar1 = new QToolBar(wnd);
                                      QAction* action1 = new QAction("test 1", m_toolBar1);
                                      action1->setText("1");
                                      m_toolBar1->addAction(action1);

                                      QToolBar* m_toolBar2 = new QToolBar(wnd);
                                      QAction* action2 = new QAction("test 2", m_toolBar2);
                                      m_toolBar2->addAction(action2);
                                      action2->setText("2");
                                      
                                      wnd->addToolBar(m_toolBar1);
                                      wnd->addToolBar(m_toolBar2);
                                      
                                      wnd->setCentralWidget(new QLabel("text"));
                                      
                                      wnd1.show();
                                      
                                      m_toolBar2->resize(200, 100);
                                      m_toolBar2->move(200, 200);
                                      
                                      return a.exec&#40;&#41;;
                                      

                                      }
                                      [/code]

                                      1 Reply Last reply
                                      0
                                      • M Offline
                                        M Offline
                                        mgran
                                        wrote on last edited by
                                        #20

                                        Hi folks, please keep this thread civil; http://qt-project.org/forums/rules

                                        @.ddriver: You need to change your screen name to something else.

                                        Project Manager - Qt Development Frameworks

                                        1 Reply Last reply
                                        0
                                        • ? This user is from outside of this forum
                                          ? This user is from outside of this forum
                                          Guest
                                          wrote on last edited by
                                          #21

                                          Is that why you deleted your profile? I assumed you were just ashamed and went for a fresh and better start, but seeing how you mock my username, which further solidifies my theory that you are indeed a jackass, I see I overestimated you. I suggest you delete that profile as well, because your behavior gives me a good reason to report you on personal basis, then make yourself a normal profile and start behaving like a grown man, not a spoiled brat.

                                          And just to assure you the methods work perfectly fine, here is a few screenshots in an animated gif and some code:

                                          !http://i39.tinypic.com/2119xmu.gif!

                                          @void MainWindow::setPos()
                                          {
                                          ui->mainToolBar->move(ui->spinX->value(), ui->spinY->value());
                                          }

                                          void MainWindow::getPos()
                                          {
                                          ui->spinX->setValue(ui->mainToolBar->pos().x());
                                          ui->spinY->setValue(ui->mainToolBar->pos().y());
                                          }@

                                          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