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 to float QToolbar on creation?

How to float QToolbar on creation?

Scheduled Pinned Locked Moved General and Desktop
6 Posts 4 Posters 8.2k 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.
  • I Offline
    I Offline
    iko5
    wrote on last edited by
    #1

    Hello,
    I'm struggling to have a toolbar floating when its created.. I have tried attaching the toolbar to the main window and setting setAllowedAreas()'s to Qt::NoToolbarArea but cannot see a correct result.

    Also I have tried setting windows flags on the toolbar toolbar->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint) and showing it. This does float the toolbar but then i cannot move it.

    Any help much appreciated, Matt

    1 Reply Last reply
    0
    • Q Offline
      Q Offline
      qttrekker
      wrote on last edited by
      #2

      Not sure if this is what you're looking for but the QToolBar class contains the setFloatable() method.
      @
      class Example : public QMainWindow
      {
      Q_OBJECT

      public:
      Example();

      private:
      QToolBar *mainToolBar;
      };

      Example::Example()
      {
      mainToolBar = addToolBar(tr("Toolbar Name"));
      mainToolBar->setMovable(true);
      mainToolBar->setFloatable(true);
      }
      @

      1 Reply Last reply
      0
      • I Offline
        I Offline
        iko5
        wrote on last edited by
        #3

        Ah nope, tired that - i think setFloatable is some sort of attribute that gets read later.. After building code similair to above the toolbar still gets added to the main window ..

        1 Reply Last reply
        0
        • R Offline
          R Offline
          rutsky
          wrote on last edited by
          #4

          In this thread http://developer.qt.nokia.com/forums/viewthread/401 author use

          @mainToolBar->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);@

          with some notes.

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on last edited by
            #5

            [quote author="rutsky" date="1330432331"]In this thread http://developer.qt.nokia.com/forums/viewthread/401 author use

            @mainToolBar->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);@

            with some notes.

            [/quote]
            While a helpful comment, I doubt the one dealing with the problem was still looking for a solution a year after posting...

            1 Reply Last reply
            0
            • R Offline
              R Offline
              rutsky
              wrote on last edited by
              #6

              [quote author="Andre" date="1330432613"]
              [quote author="rutsky" date="1330432331"]In this thread http://developer.qt.nokia.com/forums/viewthread/401 author use

              @mainToolBar->setWindowFlags(Qt::Tool | Qt::FramelessWindowHint);@

              with some notes.

              [/quote]
              While a helpful comment, I doubt the one dealing with the problem was still looking for a solution a year after posting...
              [/quote]

              I agree. I posted link to solution that worked for me for people who will search this question in future.

              Also here is my complete solution for PySide/PyQt:

              @
              from PySide import QtCore, QtGui
              #from PyQt4 import QtCore, QtGui

              def main():
              qapp = QtGui.QApplication([])

              w = QtGui.QMainWindow()
              
              t = QtGui.QToolBar(u"Toolbar")
              t.addAction(QtGui.QAction(u"action", w))
              
              w.addToolBar(QtCore.Qt.LeftToolBarArea, t)
              
              w.show()
              
              t.setAllowedAreas(QtCore.Qt.NoToolBarArea)
              t.setOrientation(QtCore.Qt.Vertical)
              p = t.mapToGlobal(QtCore.QPoint(0, 0))
              t.setWindowFlags(QtCore.Qt.Tool | QtCore.Qt.FramelessWindowHint | QtCore.Qt.X11BypassWindowManagerHint)
              t.move(p.x() + 30, p.y() + 50)
              t.adjustSize()
              
              t.show()
              
              qapp.exec_()
              

              if name == "main":
              main()
              @

              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