How to float QToolbar on creation?



  • 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



  • 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);
    }
    @



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



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

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

    with some notes.



  • [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 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()
    @


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.