zoomWidget.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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. from PyQt4.QtGui import *
  20. from PyQt4.QtCore import *
  21. class ZoomWidget(QSpinBox):
  22. def __init__(self, value=100):
  23. super(ZoomWidget, self).__init__()
  24. self.setButtonSymbols(QAbstractSpinBox.NoButtons)
  25. self.setRange(1, 500)
  26. self.setSuffix(' %')
  27. self.setValue(value)
  28. self.setToolTip(u'Zoom Level')
  29. self.setStatusTip(self.toolTip())
  30. self.setAlignment(Qt.AlignCenter)
  31. def minimumSizeHint(self):
  32. height = super(ZoomWidget, self).minimumSizeHint().height()
  33. fm = QFontMetrics(self.font())
  34. width = fm.width(str(self.maximum()))
  35. return QSize(width, height)