Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QToolbar in QMainWidnow problem
Qt 6.12 LTS is out! See what's new in the release blog

QToolbar in QMainWidnow problem

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 4.0k 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.
  • P Offline
    P Offline
    poonury
    wrote on last edited by
    #1

    Hello my dear friends!

    I want to have QToolbar on main window. He should not be dockable, should be movable and after app start should be in postion 0.0.

    If i add toolbar like this:
    addToolBar(m_pToolBar );

    On start app this is docked but shouldnt

    I try this one:
    m_pToolBar->setAllowedAreas( Qt::NoToolBarArea );
    addToolBar( Qt::ToolBarArea::NoToolBarArea,m_pToolBar );

    Now toolbar disapear. It isnt drawing.

    I force draw by setVisible but it make another window ...

    Any idea?

    1 Reply Last reply
    0
    • P Offline
      P Offline
      poonury
      wrote on last edited by
      #2

      The same problem with QDockWidget

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

        Hi,

        By default the QToolBar is floatable so you should be able to move it around already.

        As for the current code, you are explicitly telling Qt that your m_pToolBar is not allowed to dock

        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
        • A Offline
          A Offline
          alex_malyu
          wrote on last edited by
          #4

          QToolBar::QToolBar ( const QString & label, QMainWindow * mainWindow, QWidget * parent, bool newLine = FALSE, const char * name = 0, WFlags f = 0 )

          Constructs an empty horizontal toolbar.
          The toolbar is called name and is a child of parent and is managed by mainWindow. The label and newLine parameters are passed straight to QMainWindow::addDockWindow(). name and the widget flags f are passed on to the QDockWindow constructor.

          Use this constructor if you want to create torn-off (undocked, floating) toolbars or toolbars in the status bar.

          Does above help?
          Alex

          1 Reply Last reply
          0
          • P Offline
            P Offline
            poonury
            wrote on last edited by
            #5

            Alex:

            This constructor was in QT 3.x. I use QT 5.3.1 and there is not present.

            SGaist:
            I looking in source cpp and:
            addToolBar( Qt::ToolBarArea::NoToolBarArea,m_pToolBar );
            addToolBar function doesnt work because of NoToolBarArea parameter. I should use here one of 4 sides... When toolbar is docked and i undock him everything is perfect but i want to default this toolbar will be undock and here is problem.

            If you know some function that will move toolbar from dock to position x,y ( move(x,y) doesnt work ) or i dont know ...

            1 Reply Last reply
            0
            • A Offline
              A Offline
              alex_malyu
              wrote on last edited by
              #6

              Sorry working with multiple qt versions and was tired.

              I am not sure about Qt 5, but on Qt 4
              undocking is equivalent of changing window flags.

              Example below works on my computer.
              you will have to test it on QT 5:

              @ ui.toolBarFiles->setWindowFlags(Qt::Window | Qt::FramelessWindowHint);
              ui.toolBarFiles->show();
              ui.toolBarFiles->move(10,10);@

              doing this after toolbar is created will show it in undocked state.

              1 Reply Last reply
              0
              • P Offline
                P Offline
                poonury
                wrote on last edited by
                #7

                Wow this is magic... I set this falg in constructor and all was bad... Today I set this flag after add toolabr to MainWindow and work perfect...

                Thanks Alex ;)

                V 1 Reply Last reply
                0
                • P poonury

                  Wow this is magic... I set this falg in constructor and all was bad... Today I set this flag after add toolabr to MainWindow and work perfect...

                  Thanks Alex ;)

                  V Offline
                  V Offline
                  Vamsi Krishna Gali
                  wrote on last edited by
                  #8

                  @poonury I have tried this and its working fine , but when the main window is resized the floating toolbar position is not getting adjusted to new size

                  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
                  • Unsolved