zoomWidget.py 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. # Copyright (c) <2015-Present> Tzutalin
  2. # Copyright (C) 2013 MIT, Computer Science and Artificial Intelligence Laboratory. Bryan Russell, Antonio Torralba,
  3. # William T. Freeman. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and
  4. # associated documentation files (the "Software"), to deal in the Software without restriction, including without
  5. # limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the
  6. # Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  7. # The above copyright notice and this permission notice shall be included in all copies or substantial portions of
  8. # the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT
  9. # NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT
  10. # SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
  11. # CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  12. # THE SOFTWARE.
  13. try:
  14. from PyQt5.QtGui import *
  15. from PyQt5.QtCore import *
  16. from PyQt5.QtWidgets import *
  17. except ImportError:
  18. from PyQt4.QtGui import *
  19. from PyQt4.QtCore import *
  20. class ZoomWidget(QSpinBox):
  21. def __init__(self, value=100):
  22. super(ZoomWidget, self).__init__()
  23. self.setButtonSymbols(QAbstractSpinBox.NoButtons)
  24. self.setRange(1, 500)
  25. self.setSuffix(' %')
  26. self.setValue(value)
  27. self.setToolTip(u'Zoom Level')
  28. self.setStatusTip(self.toolTip())
  29. self.setAlignment(Qt.AlignCenter)
  30. def minimumSizeHint(self):
  31. height = super(ZoomWidget, self).minimumSizeHint().height()
  32. fm = QFontMetrics(self.font())
  33. width = fm.width(str(self.maximum()))
  34. return QSize(width, height)