pyqt toolbar


原文链接: pyqt toolbar

super(QToolBar, self).setFixedHeight(value)

https://github.com/tpoveda/tpQtLib/blob/da4baa56b457061bcd17fd52a4a66b64d672c035/source/tpQtLib/widgets/toolbar.py

修改toolbar的显示区域

self.addToolBar(Qt.TopToolBarArea, toolbar)

修改toolbar的大小

toolBar.setFixedHeight(36); - works well.

But if I set icon size after this:

toolBar->setFixedHeight(36);
toolBar->setIconSize(QSize(10, 10));
height breaks down. Also it happens if I set icon size via stylesheet.

Changing of calls order helps:

toolBar->setIconSize(QSize(10, 10));
toolBar->setFixedHeight(36);

super(QToolBar, self).setFixedHeight(value)

    def expand(self):
        """
        Expand the menu bar to the expand height
        """

        self._is_expanded = True
        height = self.expand_height()
        self.setFixedHeight(height)
        self.set_children_hidden(False)
        self.setIconSize(QSize(height, height))

    def collapse(self):
        """
        Collapse the menu bar to the collapse height
        """

        self._is_expanded = False
        height = self.collapse_height()
        self.setFixedHeight(height)
        self.set_children_height(0)
        self.set_children_hidden(True)
        self.setIconSize(QSize(0, 0))

设置图标大小

```py

import sys
from PyQt5 import QtCore, QtGui, QtWidgets

class Example(QtWidgets.QMainWindow):

def __init__(self):
    super().__init__()
    self.initUI()

def initUI(self):
    exitActIcon = QtGui.QIcon("./icons/outline-exit_to_app-24px.svg")
    exitAct = QtWidgets.QAction(exitActIcon, "Exit", self)
    exitAct.setShortcut("Ctrl+Q")
    exitAct.triggered.connect(QtWidgets.qApp.quit)
    self.toolbar = self.addToolBar("Exit")
    self.toolbar.addAction(exitAct)
    self.toolbar.setIconSize(QtCore.QSize(128, 128)) # <---

    self.setWindowTitle("Toolbar")
    self.show()

if name == "main":

app = QtWidgets.QApplication(sys.argv)
w = Example()
w.show()
sys.exit(app.exec_())
```
`