zoomWidget.py 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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 import QtCore
  21. from PyQt5 import QtGui
  22. from PyQt5 import QtWidgets
  23. except ImportError:
  24. from PyQt4 import QtCore
  25. from PyQt4 import QtGui
  26. from PyQt4 import QtGui as QtWidgets
  27. class ZoomWidget(QtWidgets.QSpinBox):
  28. def __init__(self, value=100):
  29. super(ZoomWidget, self).__init__()
  30. self.setButtonSymbols(QtWidgets.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(QtCore.Qt.AlignCenter)
  37. def minimumSizeHint(self):
  38. height = super(ZoomWidget, self).minimumSizeHint().height()
  39. fm = QtGui.QFontMetrics(self.font())
  40. width = fm.width(str(self.maximum()))
  41. return QtCore.QSize(width, height)