Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    How to float QToolbar on creation?

    General and Desktop
    4
    6
    7467
    Loading More Posts
    • 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
      iko5 last edited by

      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 Reply Quote 0
      • Q
        qttrekker last edited by

        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 Reply Quote 0
        • I
          iko5 last edited by

          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 Reply Quote 0
          • R
            rutsky last edited by

            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 Reply Quote 0
            • A
              andre last edited by

              [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 Reply Quote 0
              • R
                rutsky last edited by

                [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 Reply Quote 0
                • First post
                  Last post