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_OBJECTpublic:
Example();private:
QToolBar *mainToolBar;
};Example::Example()
{
mainToolBar = addToolBar(tr("Toolbar Name"));
mainToolBar->setMovable(true);
mainToolBar->setFloatable(true);
}
@ -
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, QtGuidef 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()
@