zoomWidget.py 1.5 KB

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