示例#1
0
    def sizeHint(self, option, index):
        """
        :parameters:
            option :QStyleOptionViewItem
                drawing parameters
            index : QModelIndex
                index of item
        """
        # TODO: speed this up, by caching more?
        widget = self._view.indexWidget(index)
        if widget:
            hint = widget.sizeHint()
            gridSize = 1 if self._view.showGrid() else 0
            return QtCore.QSize(hint.width(), hint.height() + gridSize)

        hint = Delegate.sizeHint(self, option, index)

        if self._view.showGrid():
            if self.MARGIN is None:
                self.MARGIN = QtGui.QApplication.style().pixelMetric(
                    QtGui.QStyle.PM_HeaderMargin, None)
            margin = self.MARGIN
            minimumHeight = max(QtGui.QApplication.globalStrut().height(),
                                option.fontMetrics.height() + margin)
            return QtCore.QSize(hint.width(), max(hint.height(),
                                                  minimumHeight))

        return hint
示例#2
0
文件: delegate.py 项目: mhamid3d/jinx
    def sizeHint(self, option, index):
        """
        Get the sizehint for a cell

        :parameters:
            option : QtGui.QStyleOption
                style information
            index : QtCore.QModelIndex
                index if the cell to draw
        :return:
            The preferred size
        :rtype:
            QtCore.QSize
        """
        # TODO: speed this up further by caching more?
        i_dataType = None
        i_model = index.model()
        if i_model:
            i_dataType = i_model.dataType(index)

        size = index.data(QtCore.Qt.SizeHintRole)
        if not size:
            option4 = QtGui.QStyleOptionViewItemV4(option)
            self.initStyleOption(option4,
                                 index,
                                 model=i_model,
                                 dataType=i_dataType)
            style = self._view.style()
            size = style.sizeFromContents(QtGui.QStyle.CT_ItemViewItem,
                                          option4, QtCore.QSize(), self._view)

        # if it is an image column and has data...
        if i_model and i_dataType == common.TYPE_IMAGE and index.data(
                QtCore.Qt.DisplayRole):
            imageHeight = int(
                self._view.topHeader().sectionSize(index.column()) /
                self.__imageCellAspectRatio
            )  # give the cell a 16/9 aspect ratio
            if imageHeight > size.height():
                size.setHeight(imageHeight)

        return size if isinstance(size, QtCore.QSize) else size.toSize()
示例#3
0
文件: common.py 项目: mhamid3d/jinx
DEFAULT_LEVEL_FILE = crosslogging.DEBUG
DEFAULT_LEVEL_QT = crosslogging.INFO

# Integer limits
# do not use sys.maxint
# the values defined here are compatible with QSpinBox widgets
MINIMUM_INTEGER = -2147483648
MAXIMUM_INTEGER = 2147483647

# Float limits
MINIMUM_FLOAT = -1.7976931348623157e+308
MAXIMUM_FLOAT = 1.7976931348623157e+308

# Default window geometry
DEFAULT_WINDOW_POS = QtCore.QPoint(50, 50)
DEFAULT_WINDOW_SIZE = QtCore.QSize(800, 600)

# log level icons
LEVEL_ICON_MAP = {
    crosslogging.CRITICAL: icons.ICON_ERROR_SML,
    crosslogging.ERROR: icons.ICON_ERROR_SML,
    crosslogging.WARNING: icons.ICON_WARNING_SML,
    crosslogging.INFO: icons.ICON_INFO_SML,
    crosslogging.VERBOSE: icons.ICON_VERBOSE_SML,
    crosslogging.DEBUG: icons.ICON_DEBUG_SML,
}

# cell edit types
EDITBITMASK_INSERT = 0x1 << 0
EDITBITMASK_DELETE = 0x1 << 1
EDITBITMASK_REVIVE = 0x1 << 2