zoomWidget.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #
  2. # Copyright (C) 2011 Michael Pitidis, Hussein Abdulwahid.
  3. #
  4. # This file is part of Labelme.
  5. #
  6. # Labelme is free software: you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License as published by
  8. # the Free Software Foundation, either version 3 of the License, or
  9. # (at your option) any later version.
  10. #
  11. # Labelme is distributed in the hope that it will be useful,
  12. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. # GNU General Public License for more details.
  15. #
  16. # You should have received a copy of the GNU General Public License
  17. # along with Labelme. If not, see <http://www.gnu.org/licenses/>.
  18. #
  19. try:
  20. from PyQt5.QtGui import *
  21. from PyQt5.QtCore import *
  22. from PyQt5.QtWidgets import *
  23. except ImportError:
  24. from PyQt4.QtGui import *
  25. from PyQt4.QtCore import *
  26. class ZoomWidget(QSpinBox):
  27. def __init__(self, value=100):
  28. super(ZoomWidget, self).__init__()
  29. self.setButtonSymbols(QAbstractSpinBox.NoButtons)
  30. self.setRange(1, 500)
  31. self.setSuffix(' %')
  32. self.setValue(value)
  33. self.setToolTip('Zoom Level')
  34. self.setStatusTip(self.toolTip())
  35. self.setAlignment(Qt.AlignCenter)
  36. def minimumSizeHint(self):
  37. height = super(ZoomWidget, self).minimumSizeHint().height()
  38. fm = QFontMetrics(self.font())
  39. width = fm.width(str(self.maximum()))
  40. return QSize(width, height)