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. Hiding/removing toolbar from QMainWindow

Hiding/removing toolbar from QMainWindow

Scheduled Pinned Locked Moved General and Desktop
qtoolbarqmainwindowpython
7 Posts 4 Posters 10.8k 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.
  • B Offline
    B Offline
    Boman
    wrote on 17 Jun 2015, 19:47 last edited by Boman
    #1

    Hello everyone,

    I am making a small app that should work as a vector graphics editor. I want to make it look like e.g. MS Paint - as a central widget of my QMainWindow I set QgraphicsScene and on the left I attached toolbar that contains different tools (they corresponds to various Qgraphicsitem which I add to the scene, which is being displayed by QgraphicsView). I also want to make different toolbars (one for each tool) that would change depending on which tool is currently chosen. I made a whole QToolbar class,(where I store the necessary info) and I can easily add it to the MainWindow (with command addToolBar). My problem is that I cannot remove it. I want to work it like this: I click icon on my left toolbar, I activate the suitable action, set it checked - toolbar appears on the screen - I can choose tool properties and draw with it - that works. Now when I want to change the tool (click different icon, set it checked and uncheck the previous one) I want the "old" toolbar to disappear and load a "new" one. Unfortunetly I can`t get rid of the old one which is still present, next to the "new" one. How can I remove it or replace it with other toolbar? I tried removeToolBar, setDisabled - none of them work the way I want. I made a picture ilustraiting my problem : http://i.imgur.com/v5jPnzL.jpg?1 I am asking for any advice that can help me solve this issue. I use PyQT 4 and Python 3.4.3 . Greetings Konrad

    M 1 Reply Last reply 28 Jan 2023, 08:50
    0
    • A Offline
      A Offline
      alex_malyu
      wrote on 17 Jun 2015, 20:54 last edited by
      #2

      To hide toolbar you call close(), like
      ui.toolBar->close();

      to delete
      delete ui.toolBar;

      A 1 Reply Last reply 17 Jun 2015, 20:59
      0
      • A alex_malyu
        17 Jun 2015, 20:54

        To hide toolbar you call close(), like
        ui.toolBar->close();

        to delete
        delete ui.toolBar;

        A Offline
        A Offline
        alex_malyu
        wrote on 17 Jun 2015, 20:59 last edited by
        #3

        but I would consider to add toolbar to your view or use concept of the active view ( best when controls for each view are the same) and share mainwindow toolbar.

        1 Reply Last reply
        0
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 17 Jun 2015, 20:59 last edited by
          #4

          Hi and welcome to devnet,

          Looks like your implementing an equivalent of toggleViewAction

          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
          0
          • B Offline
            B Offline
            Boman
            wrote on 18 Jun 2015, 16:06 last edited by Boman
            #5

            Thank you all for advices. I used toggleViewAction and it works great. I can show and hide toolbar whenever I click on the Icon. Unfortunetly one problem is gone, another appeared. After I click the icon and the toggleAction is checked I want to change a value of a variable that indicates which tool is currently active. To do that I need some indicator which action was triggerd. Las time it was easy, because i changed the value in the function to which the action was connected. How can I achive the same goal now with toggleaction? I tried isChecked(), isEnabled(), isVisible() to get the info which action is active but it didn`t work.

            Update:
            The solution to this problem was trivial. I just connected the ToggleAction to function(triggered signal). Thanks for advices anyway.

            1 Reply Last reply
            0
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 18 Jun 2015, 20:30 last edited by
              #6

              What kind of indicator do you mean ?

              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
              0
              • B Boman
                17 Jun 2015, 19:47

                Hello everyone,

                I am making a small app that should work as a vector graphics editor. I want to make it look like e.g. MS Paint - as a central widget of my QMainWindow I set QgraphicsScene and on the left I attached toolbar that contains different tools (they corresponds to various Qgraphicsitem which I add to the scene, which is being displayed by QgraphicsView). I also want to make different toolbars (one for each tool) that would change depending on which tool is currently chosen. I made a whole QToolbar class,(where I store the necessary info) and I can easily add it to the MainWindow (with command addToolBar). My problem is that I cannot remove it. I want to work it like this: I click icon on my left toolbar, I activate the suitable action, set it checked - toolbar appears on the screen - I can choose tool properties and draw with it - that works. Now when I want to change the tool (click different icon, set it checked and uncheck the previous one) I want the "old" toolbar to disappear and load a "new" one. Unfortunetly I can`t get rid of the old one which is still present, next to the "new" one. How can I remove it or replace it with other toolbar? I tried removeToolBar, setDisabled - none of them work the way I want. I made a picture ilustraiting my problem : http://i.imgur.com/v5jPnzL.jpg?1 I am asking for any advice that can help me solve this issue. I use PyQT 4 and Python 3.4.3 . Greetings Konrad

                M Offline
                M Offline
                mingxingz
                wrote on 28 Jan 2023, 08:50 last edited by mingxingz
                #7

                @Boman if the tool bar was set using addToolBar(toolbarWidget), you can show and hide the toolbarWidget to achieve your purpose

                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