Issue
I'm trying to create a desktop app with modern looking user-interface, by that I mean specifically replacing traditional menubar and toolbar with ribbon menu, e.g like one from MS Office suite.
I have achieved some progress working with QToolBar (with QActions) stacked into QTabWidget, but the problem was, it showed correctly only when I set it as CentralWidget. Later, when I wanted to implement table (QTableWidget), it failed showing anything but the table...
Method for ribbon:
def tab_menu(self):
self.tabWidget = QTabWidget()
self.tabWidget.setFixedHeight(120)
self.setCentralWidget(self.tabWidget)
self.tab1 = QFrame()
layout = QGridLayout()
addFile = QAction('Add entry', self)
addFile.setIcon(icon1)
removeFile = QAction('Remove entry', self)
removeFile.setIcon(icon2)
addFolder = QAction('New category', self)
addFolder.setIcon(icon3)
removeFolder = QAction('Remove category', self)
removeFolder.setIcon(icon4)
editFile = QAction('Change entry', self)
editFile.setIcon(icon5)
toolBar = QToolBar()
toolBar.addAction(addFile)
toolBar.addAction(removeFile)
toolBar.addAction(editFile)
toolBar.addSeparator()
toolBar.addAction(addFolder)
toolBar.addAction(removeFolder)
icon_width = 60
toolBar.setIconSize(QSize(icon_width, icon_width))
layout.setAlignment(Qt.AlignLeft)
layout.addWidget(toolBar, 0, 0)
self.tab1.setLayout(layout)
self.tabWidget.addTab(self.tab1, 'Edit')
self.tabWidget.show()
I would like to know how is it possible to "anchor" the QTabWidget to place, where should be toolbar/menubar. I saw the layout shown at https://doc.qt.io/qt-5/qmainwindow.html, but I'm not certain how to use it.
Solution
This is an old question, but it's a pity it was left unanswered.
If you wanted a fixed position of a RibbonBar
, you can simply insert it into a QWidget
container, divide your form using QVBoxLayout
and stuff that QWidget
into the first (that is the top) part.
Whereas, if you really wanted to use QDockWidgetArea
s, then you'd have to use a QDockWidget
as a parent container and place it into the TopDockWidgetArea
, which would then be only a default position and user would be able to move it. Perhaps there's a way to use Qt.TopToolBarArea
too, but I haven't tried.
But I wonder, if one can freely use the Ribbonbar idea. I saw some discussions about patents preventing developers from using it.
Answered By - Oak_3260548
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.