自己最近做的軟件需要一個工具欄,然後點擊工具欄的圖標需要進行一定的操作
- 創建工具欄
toolBar
- 主窗口添加工具欄
addToolBar
- 創建工具按鈕
refresf_button
- 按鈕添加圖標與文字
- 連接按鈕點擊事件
- 工具欄添加按鈕
toolBar.addWidget(refrefh_botton)
self.toolBar = QToolBar(MainWindow)
self.toolBar.setObjectName("toolBar")
self.toolBar.setContentsMargins(QMargins(20, 0, 20, 0))
MainWindow.addToolBar(Qt.TopToolBarArea, self.toolBar)
self.refresh_button = QPushButton()
self.refresh_button.setText('刷新')
refresh_icon = QIcon()
refresh_icon.addPixmap(QPixmap('../images/refresh.png'), QIcon.Normal, QIcon.Off)
self.refresh_button.setIcon(refresh_icon)
self.refresh_button.setIconSize(QSize(25, 25))
self.refresh_button.setStyleSheet(QSS.ButtonStyle)
self.refresh_button.clicked.connect(self.refresh_treewidget)
self.toolBar.addWidget(self.refresh_button)