如何拥有多个工具栏

2024-05-02 07:01:39 发布

您现在位置:Python中文网/ 问答频道 /正文

我想在顶部有两个工具栏,但它们只是保持在一起

#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)


Tags: theselfmain图片qt工具栏toolbaraddaction
1条回答
网友
1楼 · 发布于 2024-05-02 07:01:39

根据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.

也就是说,它将它置于before的位置,取代了这个位置,正如我们所观察到的,这就是它所实现的,但它不是你所期望的

您必须使用^{}

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

相关问题 更多 >