python - 如何拥有多个工具栏

标签 python python-2.7 python-3.x pyqt pyqt4

我想在顶部有两个工具栏,但它们只是彼此重叠

#The main toolbar 
self.formatbar = QToolBar() 

self.addToolBar( Qt.TopToolBarArea , self.formatbar )
self.formatbar.addSeparator()
self.formatbar.addWidget(self.fontComboBox)
self.formatbar.addWidget(self.fontSizeComboBox)
self.formatbar.addAction(closeActionTB)
self.formatbar.addAction(openActionTB)
self.formatbar.addAction(saveActionTB)
self.formatbar.addAction(capitalActionTB)
self.formatbar.addAction(smallActionTB)
self.formatbar.addAction(colorActionTB)
self.formatbar.addAction(colorActionBGTB)
self.formatbar.addAction(zoomInActionTB)
self.formatbar.addAction(zoomOutActionTB)
self.formatbar.addAction(changeBoldActionTB)
self.formatbar.addAction(changeItalicActionTB)
self.formatbar.addAction(changeFontUnderlineActionTB)
self.formatbar.addAction(undoActionTB)
self.formatbar.addAction(redoActionTB)
self.formatbar.addAction(magnifyTB)
self.formatbar.addAction(demagnifyTB)
self.formatbar.addAction(printActionTB)
self.formatbar.addAction(findActionTB)
self.formatbar.addAction(alLeftTB)
self.formatbar.addAction(alRightTB)
self.formatbar.addAction(alCenterTB)
self.formatbar.addAction(alJustifyTB)
self.formatbar.addAction(bulletListActionTB)
self.formatbar.addAction(numberListActionTB)

#here the toolbar finishes so i want a new toolbar       
self.formatbar2 = QToolBar()
self.insertToolBar(self.formatbar,self.formatbar2)
self.formatbar2.addAction(indentTB) 
self.formatbar2.addAction(deindentTB)
self.formatbar2.addAction(clearTB)
self.formatbar.addAction(copyRightsTB)

第一张图片是工具栏现在的样子,第二张图片是我想要的样子

This is how the tool bar is right now

This is how i want i want it(i put it there manually)

最佳答案

根据docs :

void QMainWindow::insertToolBar(QToolBar *before, QToolBar *toolbar)

Inserts the toolbar into the area occupied by the before toolbar so that it appears before it. For example, in normal left-to-right layout operation, this means that toolbar will appear to the left of the toolbar specified by before in a horizontal toolbar area.

也就是说,它将它放置在之前的位置,取代了它,正如我们所观察到的,这就是它所完成的任务,但它不是您所期望的。

您必须使用addToolBarBreak :

void QMainWindow::addToolBarBreak(Qt::ToolBarArea area = Qt::TopToolBarArea)

Adds a toolbar break to the given area after all the other objects that are present.

就您而言:

self.formatbar = QToolBar()
self.addToolBar( Qt.TopToolBarArea , self.formatbar )
# add actions and widgets
self.addToolBarBreak(Qt.TopToolBarArea) # or self.addToolBarBreak()
self.formatbar2 = QToolBar()
self.addToolBar( Qt.TopToolBarArea , self.formatbar2)
# add actions and widgets

关于python - 如何拥有多个工具栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45267848/

相关文章:

python - 附加到列表时未调用 Setattr 方法

python - 绘制远离 y 轴的非数字 x 轴

python - 在 os X 10.7 Lion 上设置 Django 的最佳方法是什么?

python - TkInter:利用错误的位置

javascript - 如何从 chrome 扩展 POST 到 flask-security 端点?

python-3.x - 是否可以交互式编辑 matplotlib 图?

python - 为什么对于不可变列表的浅复制和深复制没有区别

python - Pymysql无法导入python3

python - 在没有python的电脑上运行程序

python-3.x - 如何制定正确的训练和测试维度以适合 elmo 嵌入模型