2018년 11월 21일 수요일

[PyQt5] QWidgetAction sample

# -*- coding: utf-8 -*-
import sys

from PyQt5.QtWidgets import QMainWindow, QApplication, QWidgetAction, QMenu


class Example(QMainWindow):

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

      self.toolbar = self.addToolBar('Toolbar')
      self.widgetAction = QWidgetAction(self.toolbar)
      self.menu = QMenu(self.toolbar)

      self.action1 = self.menu.addAction('action1')
      self.action2 = self.menu.addAction('action2')

      self.widgetAction.setText('demo')
      self.widgetAction.setMenu(self.menu)
      self.toolbar.addAction(self.widgetAction)

      self.action1.triggered.connect(self.onAction1)
      self.action2.triggered.connect(self.onAction2)

      self.widgetAction.triggered.connect(self.triggered)

      self.setGeometry(300, 300, 300, 200)
      self.setWindowTitle('Toolbar')

   def triggered(self, e):
      if self.widgetAction.text() == 'onAction1':
         self.action1.trigger()
      elif self.widgetAction.text() == 'onAction2':
         self.action2.trigger()

   def onAction1(self):
      print('onAction1')
      self.widgetAction.setText('onAction1')

   def onAction2(self):
      print('onAction2')
      self.widgetAction.setText('onAction2')


if __name__ == '__main__':
   app = QApplication(sys.argv)
   ex = Example()
   ex.show()
   sys.exit(app.exec_())

댓글 없음:

댓글 쓰기

docker redmine 설치

docker-composer.yml version: '3.1' services:      redmine:           image: redmine           restart: always           container_na...