def __init__(self, rect=None, parent=None): self.signals = CurveNodeItemSignals() gradient = QRadialGradient( self.WIDTH * 0.75, self.WIDTH * 0.75, self.WIDTH * 0.75, self.WIDTH * 0.75, self.WIDTH * 0.75) gradient.setColorAt(0, self.theme().accent_color_6 if self.theme() else QColor.fromRgbF(1, 0.5, 0.01, 1)) gradient.setColorAt(1, self.theme().accent_color_8 if self.theme() else QColor.fromRgbF(1, 0.6, 0.06, 1)) self._brush = QBrush(gradient) self._brush.setStyle(Qt.RadialGradientPattern) self._pen = QPen() self._pen.setStyle(Qt.SolidLine) self._pen.setWidth(2) self._pen.setColor(self.theme().accent_color if self.theme() else QColor(104, 104, 104, 255)) self._selected_pen = QPen() self._selected_pen.setStyle(Qt.SolidLine) self._selected_pen.setWidth(3) self._selected_pen.setColor(self.theme().accent_color_4 if self.theme() else QColor(67, 255, 163, 255)) super(CurveNodeItem, self).__init__(parent) self._lock_x_pos = False self._snap = False self._current_pos = None self._new_pos = None self._line = None self._is_point1 = False self.set_rect(rect if rect else QRect(0, 0, 10, 10)) self.setFlags( QGraphicsItem.ItemIsMovable | QGraphicsItem.ItemIsSelectable | QGraphicsItem.ItemSendsScenePositionChanges)
def color_from_string(string, alpha): xs = string.strip() regex = QRegExp(REGEX_QCOLOR) match = regex.exactMatch(xs) if match: return QColor(xs) regex = QRegExp(REGEX_FN_RGB) match = regex.exactMatch(xs) if match: captured_texts = regex.capturedTexts() return QColor(int(captured_texts[-3]), int(captured_texts[-2]), int(captured_texts[-1])) if alpha: regex = QRegExp(REGEX_HEX_RGBA) match = regex.exactMatch(xs) if match: return QColor(_HEXDEC[xs[1:3]], _HEXDEC[xs[3:5]], _HEXDEC[xs[5:7]], _HEXDEC[xs[7:9]]) regex = QRegExp(REGEX_FN_RGBA) match = regex.exactMatch(xs) if match: captured_texts = regex.capturedTexts() return QColor( int(captured_texts[-4]), int(captured_texts[-3]), int(captured_texts[-2]), int(captured_texts[-1])) return QColor()
def get_syntax_format(color=None, style=''): """ Returns a QTextCharFormat with the given attributes. """ _color = None if type(color) == str: _color = QColor() _color.setNamedColor(color) if type(color) == list: _color = QColor(*color) if color == 'green': _color = Qt.green _format = QTextCharFormat() if _color: _format.setForeground(_color) if 'bold' in style: _format.setFontWeight(QFont.Bold) if 'italic' in style: _format.setFontItalic(True) return _format
class GridColors(object): """ Class that stores predefined colors for grids """ BaseColor = QColor(60, 60, 60, 100) DarkerColor = QColor(20, 20, 20, 100)
def paintEvent(self, event): painter = QPainter() painter.begin(self) painter.setBrush(QColor(192, 192, 192)) painter.setPen(QColor(64, 64, 64)) painter.drawPolygon(self._arrow) painter.end()
def paint(self, painter, option, index): painter.setRenderHints(QPainter.Antialiasing | QPainter.SmoothPixmapTransform) model = index.model() view = self.parent() if view.hasFocus() and option.state & QStyle.State_MouseOver: painter.setPen(Qt.NoPen) painter.setBrush(Qt.gray) painter.drawRoundedRect(option.rect.adjusted(1, 1, -1, -1), self._ICON_MARGIN, self._ICON_MARGIN) pixmap = model.data(index, Qt.DecorationRole).pixmap(view.iconSize()) pm_rect = QRect( option.rect.topLeft() + QPoint(self._ICON_MARGIN + 1, self._ICON_MARGIN + 1), view.iconSize() - QSize(self._ICON_MARGIN * 2, self._ICON_MARGIN * 2)) painter.drawPixmap(pm_rect, pixmap) if option.state & QStyle.State_Selected: painter.setPen( QPen(Qt.red, 1.0, Qt.SolidLine, Qt.SquareCap, Qt.RoundJoin)) painter.setBrush(Qt.NoBrush) painter.drawRect(option.rect.adjusted(2, 2, -2, -2)) font = view.font() fm = QFontMetrics(font) text = os.path.splitext( os.path.basename(model.data(index, Qt.DisplayRole)))[0] text = fm.elidedText(text, Qt.ElideRight, view.iconSize().width() - 4) text_opt = QTextOption() text_opt.setAlignment(Qt.AlignHCenter) txt_rect = QRectF(QPointF(pm_rect.bottomLeft() + QPoint(0, 1)), QPointF(option.rect.bottomRight() - QPoint(4, 3))) painter.save() painter.setPen(Qt.NoPen) painter.setBrush(QColor(22, 22, 22, 220)) painter.drawRoundedRect(txt_rect.adjusted(-2, -2, 2, 2), 2, 2) painter.restore() painter.setPen(self.parent().palette().color(QPalette.WindowText)) painter.drawText(txt_rect, text, text_opt) font.setPointSize(8) fm = QFontMetrics(font) item = model.itemFromIndex(index) size_text = '%d x %d' % (item.size.width(), item.size.height()) size_rect = fm.boundingRect(option.rect, Qt.AlignLeft | Qt.AlignTop, size_text) size_rect.translate(4, 4) painter.save() painter.setPen(Qt.NoPen) painter.setBrush(QColor(22, 22, 22, 220)) painter.drawRoundedRect(size_rect.adjusted(-2, -2, 2, 2), 2, 2) painter.restore() painter.setFont(font) painter.drawText(size_rect, size_text)
def __init__(self, parent=None, **kwargs): QGraphicsItem.__init__(self, parent=parent) self.enabled = kwargs.get('enabled', True) self.color = kwargs.get('color', QColor(31, 32, 33, 255)) self.disabled_color = kwargs.get('disabled_color', QColor(125, 125, 125, 255)) self.selected_color = kwargs.get('selected_color', QColor(30, 35, 40, 255)) self.disabled_border_width = kwargs.get('disabled_border_width', 1.5) self.selected_border_width = kwargs.get('selected_border_width', 1.5) self.disabled_border_color = kwargs.get('disabled_border_color', QColor(40, 40, 40, 255)) self.selected_border_color = kwargs.get('selected_border_color', QColor(250, 210, 90, 255)) self.disabled_shadow_color = kwargs.get('disabled_shadow_color', QColor(35, 35, 35, 60)) self.selected_shadow_color = kwargs.get('selected_shadow_color', QColor(105, 55, 0, 60)) self.disabled_border_style = kwargs.get('disabled_border_style', Qt.DashDotLine) self.selected_border_style = kwargs.get('selected_border_style', Qt.DashLine) self._border_width = kwargs.get('border_width', 1.5) self._shadow_color = kwargs.get('shadow_color', QColor(0, 0, 0, 60)) self._border_color = kwargs.get('border_color', QColor(10, 10, 10, 255)) self._border_type = kwargs.get('border_type', Qt.SolidLine) self._current_pos = QPointF(0, 0) self._new_pos = QPointF(0, 0) self._width = kwargs.get('width', 120) self._height = kwargs.get('height', 40) self._sizes = [0, 0, self._width, self._height, 7, 7] # [x, y, width, height, radius_x, radius_x] self._is_hovered = False self._render_effects = True
def background_color(self): if not self.enabled: return self.disabled_color if self.selected: # return QColor(*[255, 183, 44]) return self.selected_color if self.hovered: base_color = QColor(self.color) return base_color.lighter(150) return QColor(self.color)
def main(): import sys a = QApplication(sys.argv) acmeSeries = QCandlestickSeries() acmeSeries.setName("Acme Ltd") acmeSeries.setIncreasingColor(QColor(Qt.green)) acmeSeries.setDecreasingColor(QColor(Qt.red)) acmeData = QFile(":acme") if not acmeData.open(QIODevice.ReadOnly | QIODevice.Text): sys.exit(1) categories = [] dataReader = CandlestickDataReader(acmeData) while not dataReader.atEnd(): _set = dataReader.readCandlestickSet() if _set is not None: acmeSeries.append(_set) categories.append( QDateTime.fromMSecsSinceEpoch(int( _set.timestamp())).toString("dd")) chart = QChart() chart.addSeries(acmeSeries) chart.setTitle("Acme Ltd Historical Data (July 2015)") chart.setAnimationOptions(QChart.SeriesAnimations) chart.createDefaultAxes() axisX = chart.axes(Qt.Horizontal)[0] axisX.setCategories(categories) axisY = chart.axes(Qt.Vertical)[0] axisY.setMax(axisY.max() * 1.01) axisY.setMin(axisY.min() * 0.99) chart.legend().setVisible(True) chart.legend().setAlignment(Qt.AlignBottom) chartView = QChartView(chart) chartView.setRenderHint(QPainter.Antialiasing) window = QMainWindow() window.setCentralWidget(chartView) window.resize(800, 600) window.show() sys.exit(a.exec_())
class BaseGraphicWidget(QGraphicsWidget, object): DEFAULT_GRAPHIC_WIDGET_COLOR = QColor(0, 100, 0, 255) DEFAULT_GRAPHIC_WIDGET_BORDER_COLOR = QColor(0, 0, 0, 255) def __init__(self, name, color=DEFAULT_GRAPHIC_WIDGET_COLOR, border_color=DEFAULT_GRAPHIC_WIDGET_BORDER_COLOR): super(BaseGraphicWidget, self).__init__() self._name = name.strip().replace(' ', '_') self._color = color self._border_color = border_color self._hovered = False def get_name(self): return self._name def set_name(self, name): self._name = name def get_color(self): return self._color def set_color(self, color): self._color = color def get_border_color(self): return self._border_color def set_border_color(self, border_color): self._border_color = border_color def set_hovered(self, flag): self._hovered = flag def get_hovered(self): return self._hovered name = property(get_name, set_name) color = property(get_color, set_color) border_color = property(get_border_color, set_border_color) hovered = property(get_hovered, set_hovered) def hoverEnterEvent(self, *args, **kwargs): self.update() self._hovered = True def hoverLeaveEvent(self, *args, **kwargs): self.update() self._hovered = False
def __init__(self, baseColor=QColor("#f7f7f7"), highlightColor=QColor("#2196F3"), spread=2.5): """Constructor By default a nukeish color scheme (dark slate + orange highlight) is created This can be overriden by either supplying colors or by loading a different scheme from disc via the load settings """ self.palette = QPalette() self.baseColor = baseColor self.highlightColor = highlightColor self.spread = spread self.generateScheme() QApplication.setStyle("Plastique")
def drawBackground(self, painter, rect): super(GridView, self).drawBackground(painter, rect) if self._show_grid: scene_rect = self.sceneRect() left = int(scene_rect.left()) - (int(scene_rect.left()) % self._draw_grid_size) top = int(scene_rect.top()) - (int(scene_rect.top()) % self._draw_grid_size) scale_mult = 1.0 lines = list() left_line = rect.left() - rect.left() % self._grid_size top_line = rect.top() - rect.top() % self._grid_size i = int(left_line) while i < int(rect.right()): lines.append(QLineF(i, rect.top(), i, rect.bottom())) i += self._grid_size u = int(top_line) while u < int(rect.bottom()): lines.append(QLineF(rect.left(), u, rect.right(), u)) u += self._grid_size # TODO: Change pen to a class variable (avoid to create a pen each drawing frame) pen = QPen() pen.setWidth(0) pen.setColor(QColor(20, 20, 20)) painter.setPen(pen) painter.drawLines(lines)
def create_empty_image(output=None, resolution_x=1920, resolution_y=1080, background_color=None): """ Creates an empty image and stores it in the given path :param output: str :param resolution_x: int :param resolution_y: int :param background_color: list(int, int, int) :return: str or QImage """ if background_color is None: background_color = [0, 0, 0] pixmap = QPixmap(resolution_x, resolution_y) pixmap.fill(QColor(*background_color)) if output: output_path = path_utils.clean_path(output) output_dir = os.path.dirname(output_path) if os.access(output_dir, os.W_OK): pixmap.save(output_path) return output_path return QImage(pixmap)
def paint_background(image, background_color=None): """ Paints a background of the given color into the given QImage :param image: QImage :param background_color: tuple(r, g, b) :return: QImage, image with painted background """ if not background_color: background_color = [0, 0, 0] if type(background_color) not in (list, tuple) or len(background_color) != 3: LOGGER.warning( 'background_color argument is not valid ({}) using black color instead!' .format(background_color)) background_color = [0, 0, 0] background_color = python.force_list(background_color) for i in range(len(background_color)): if background_color[i] < 0 or background_color[i] > 255: LOGGER.warning( 'Background color channel ({})({}) out of limit (0, 255). Fixing to fit range ...' .format(i, background_color[i])) background_color[i] = min(max(background_color[i], 0), 255) image.fill(QColor(*background_color).rgb()) return image
def paintEvent(self, event): super(DragDoubleSpinBoxLine, self).paintEvent(event) p = QPainter() p.begin(self) try: v = float(self.text()) except Exception: v = 0.0000001 try: v /= self._max if v > 0 else (self._min * -1) except Exception: pass if self._sup: p.fillRect(QRect(0, self.height() - 4, v * self.width(), 4), self._color) else: p.fillRect( QRect(self.width() * 0.5, self.height() - 4, v * self.width() * 0.5, 4), self._color if v > 0 else QColor(255, 0, 0)) p.end()
def color_from_lch(hue, chroma, luma, alpha=1): h1 = hue * 6 x = chroma * (1 - abs(math.fmod(h1, 2) - 1)) col = QColor() if 0 <= h1 < 1: col = QColor.fromRgbF(chroma, x, 0) elif h1 < 2: col = QColor.fromRgbF(x, chroma, 0) elif h1 < 3: col = QColor.fromRgbF(0, chroma, x) elif h1 < 4: col = QColor.fromRgbF(0, x, chroma) elif h1 < 5: col = QColor.fromRgbF(x, 0, chroma) elif h1 < 6: col = QColor.fromRgbF(chroma, 0, x) m = luma - color_luma_float(col) return QColor.fromRgbF( clamp(col.redF() + m, 0.0, 1.0), clamp(col.greenF() + m, 0.0, 1.0), clamp(col.blueF() + m, 0.0, 1.0), alpha )
def color_from_hsl(hue, sat, lig, alpha): chroma = (1 - abs(2 * lig - 1)) * sat h1 = hue * 6 x = chroma * (1 - abs(math.fmod(h1, 2) - 1)) col = QColor() if 0 <= h1 < 1: col = QColor.fromRgbF(chroma, x, 0) elif h1 < 2: col = QColor.fromRgbF(x, chroma, 0) elif h1 < 3: col = QColor.fromRgbF(0, chroma, x) elif h1 < 4: col = QColor.fromRgbF(0, x, chroma) elif h1 < 5: col = QColor.fromRgbF(x, 0, chroma) elif h1 < 6: col = QColor.fromRgbF(chroma, 0, x) m = lig - chroma / 2 return QColor.fromRgbF( clamp(col.redF() + m, 0.0, 1.0), clamp(col.greenF() + m, 0.0, 1.0), clamp(col.blueF() + m, 0.0, 1.0), alpha )
def paint_background(self, painter, option, index): """ Overrides base paint_background icon function Draw the background for the item :param painter: QPainter :param option: QStyleOptionViewItem :param index: QModelIndex """ super(GroupDataItemView, self).paint_background(painter, option, index) painter.setPen(QPen(Qt.NoPen)) visual_rect = self.visualRect(option) text = self.name() metrics = QFontMetrics(self._font) text_width = metrics.width(text) padding = (25 * self.dpi()) visual_rect.setX(text_width + padding) visual_rect.setY(visual_rect.y() + (visual_rect.height() / 2)) visual_rect.setHeight(2 * self.dpi()) visual_rect.setWidth(visual_rect.width() - padding) color = QColor(self.text_color().red(), self.text_color().green(), self.text_color().blue(), 10) painter.setBrush(QBrush(color)) painter.drawRect(visual_rect)
def backgroundColor(self): """ Overrides base sizeHint backgroundColor function Return the background color for the item. :rtype: QtWidgets.QtColor """ return QColor(0, 0, 0, 0)
def __init__(self, label_text='', slider_type='float', buttons=False, decimals=3, dragger_steps=None, apply_style=True, main_color=None, *args, **kwargs): super(DraggerSlider, self).__init__(*args, **kwargs) self._label_text = label_text self._main_color = main_color if main_color else QColor(215, 128, 26).getRgb() self._dragger_steps = dragger_steps or FLOAT_SLIDER_DRAG_STEPS self._is_float = slider_type == 'float' self._draggers = None self.setFocusPolicy(Qt.StrongFocus) if not self._is_float: self.setDecimals(0) self.setRange(qtutils.FLOAT_RANGE_MIN, qtutils.FLOAT_RANGE_MAX) else: self.setDecimals(decimals) self.setRange(qtutils.INT_RANGE_MIN, qtutils.INT_RANGE_MAX) if not buttons: self.setButtonSymbols(QAbstractSpinBox.NoButtons) if apply_style: self._label_font = QFont('Serif', 10, QFont.Bold) self.setStyleSheet(self._get_style_sheet()) else: self._label_font = self.lineEdit().font() self.lineEdit().installEventFilter(self) self.installEventFilter(self)
def __init__(self, parent=None, is_float=True, dragger_steps=None, main_color=None): super(SliderDraggers, self).__init__(parent) self._drags = list() self._initial_pos = None self._active_drag = None self._last_delta_x = 0 self._change_direction = 0 self._main_color = main_color if main_color else QColor(215, 128, 26).getRgb() dragger_steps = dragger_steps or FLOAT_SLIDER_DRAG_STEPS self.setWindowFlags(Qt.Popup) draggers_layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) self.setLayout(draggers_layout) steps = copy(dragger_steps) if not is_float: steps = list(filter(lambda x: abs(x) >= 1.0, steps)) for i in steps: drag = HoudiniInputDragger(self, i) self._drags.append(drag) draggers_layout.addWidget(drag) self.installEventFilter(self)
def __init__(self, parent, factor, main_color=None, *args, **kwargs): super(HoudiniInputDragger, self).__init__(*args, **kwargs) self._parent = parent self._factor = factor self._main_color = main_color if main_color else QColor(215, 128, 26).getRgb() self._size = 35 self.setAttribute(Qt.WA_Hover) self.setStyleSheet(self._get_style_sheet()) self.setMinimumHeight(self._size) self.setMinimumWidth(self._size) self.setMaximumHeight(self._size) self.setMaximumWidth(self._size) main_layout = layouts.VerticalLayout(margins=(0, 0, 0, 0)) self.setLayout(main_layout) frame_layout = layouts.VerticalLayout(spacing=0, margins=(0, 0, 0, 0)) self._frame = QGroupBox() self._frame.setLayout(frame_layout) main_layout.addWidget(self._frame) self._label = label.BaseLabel('+' + str(factor), parent=self) font = self._label.font() font.setPointSize(7) self._label.setFont(font) self._label.setAlignment(Qt.AlignCenter) frame_layout.addWidget(self._label) self.installEventFilter(self) self._label.installEventFilter(self)
def paintEvent(self, event): if self.isVisible() and self.paintLineNum > 0: # NOTE 更新绘制 self.viewport().update() block = self.firstVisibleBlock() height = self.lineNumberArea.fontMetrics().height() number = block.blockNumber() painter = QPainter(self.viewport()) condition = True while block.isValid() and condition: block_geometry = self.blockBoundingGeometry(block) offset = self.contentOffset() block_top = block_geometry.translated(offset).top() number += 1 block_rect = QRect(0, block_top, self.width(), height) if number == self.paintLineNum: lineColor = QColor(LINE_COLOR).lighter(100) painter.fillRect(block_rect, lineColor) painter.drawRect(block_rect) condition = False if block_top > event.rect().bottom(): condition = False block = block.next() painter.end() return super(CodeEditor, self).paintEvent(event)
def __init__(self, parent=None, **kwargs): super(ColorPicker, self).__init__(parent=parent, **kwargs) self._default_value = (125, 125, 125) self.attr = None self.normalized = kwargs.get('normalized', False) self.min = kwargs.get('min', 0) self.max = kwargs.get('max', 99) self.color = kwargs.get('color', QColor(1.0, 1.0, 1.0)) self.mult = kwargs.get('mult', 0.1) self.color_swatch = color.ColorSwatch(parent=self, color=self.color, normalized=self.normalized) self.color_swatch.setMaximumSize(QSize(75, 20)) self.color_swatch.setMinimumSize(QSize(75, 20)) self.color_swatch.set_color(color=self.color) self.main_layout.addWidget(self.color_swatch) self.slider = QSlider(self) self.slider.setOrientation(Qt.Horizontal) self.slider.setValue(self.max) self.main_layout.addWidget(self.slider) self.set_max(self.max) self.set_min(self.min) self.slider.valueChanged.connect(self.OnSliderChanged) self.slider.sliderReleased.connect(self.OnSliderReleased) self.color_swatch.clicked.connect(self.OnColorPicked)
def addItems(self): itemCount = self.itemTable.rowCount() imageOffset = 150 leftMargin = 70 topMargin = 40 for i in range(itemCount): record = self.itemTable.record(i) id_ = record.value("id") file = record.value("file") item = record.value("itemtype") columnOffset = (i % 2) * 37 x = ((i % 2) * imageOffset) + leftMargin + columnOffset y = ((i / 2) * imageOffset) + topMargin image = ImageItem(id_, QPixmap(":/" + file)) image.setData(0, i) image.setPos(x, y) self.scene.addItem(image) label = self.scene.addText(item) label.setDefaultTextColor(QColor("#d7d6d5")) labelOffset = QPointF((120 - label.boundingRect().width()) / 2, 120.0) label.setPos(QPointF(x, y) + labelOffset)
def drawSizeInfo(self): sizeInfoAreaWidth = 200 sizeInfoAreaHeight = 30 spacing = 5 rect = self.selectedArea.normalized() sizeInfoArea = QRect(rect.left(), rect.top() - spacing - sizeInfoAreaHeight, sizeInfoAreaWidth, sizeInfoAreaHeight) if sizeInfoArea.top() < 0: sizeInfoArea.moveTopLeft(rect.topLeft() + QPoint(spacing, spacing)) if sizeInfoArea.right() >= self.screenPixel.width(): sizeInfoArea.moveTopLeft(rect.topLeft() - QPoint(spacing, spacing) - QPoint(sizeInfoAreaWidth, 0)) if sizeInfoArea.left() < spacing: sizeInfoArea.moveLeft(spacing) if sizeInfoArea.top() < spacing: sizeInfoArea.moveTop(spacing) self.itemsToRemove.append( self.graphicsScene.addRect(QRectF(sizeInfoArea), QPen(Qt.white), QBrush(Qt.black))) sizeInfo = self.graphicsScene.addSimpleText(' {0} x {1}'.format( rect.width() * self.scale, rect.height() * self.scale)) sizeInfo.setPos(sizeInfoArea.topLeft() + QPoint(0, 2)) sizeInfo.setPen(QPen(QColor(255, 255, 255), 2)) self.itemsToRemove.append(sizeInfo)
def _line_number_highlight(self): extra_selection = QTextEdit.ExtraSelection() selections = [extra_selection] if not self.isReadOnly(): selection = QTextEdit.ExtraSelection() if dcc.is_maya(): line_color = QColor(Qt.black) else: line_color = QColor(Qt.lightGray) selection.format.setBackground(line_color) selection.format.setProperty(QTextFormat.FullWidthSelection, True) selection.cursor = self.textCursor() selection.cursor.clearSelection() selections.append(selection) self.setExtraSelections(selections)
def setButtonColor(self, button, color): qcolor = QColor() qcolor.setRgbF(color[0], color[1], color[2]) palette = QPalette() palette.setColor(QPalette.Button, qcolor) button.setPalette(palette)
def setIcon(self, column, icon, color=None): """ Overrides base QTreeWidgetItem setIcon function :param column: int or str :param icon: QIcon :param color: QColor or None """ is_app_running = bool(QApplication.instance()) if not is_app_running: return if python.is_string(icon): if not os.path.exists(icon): color = color or QColor(255, 255, 255, 20) icon = resources.icon('image', color=color) else: icon = QIcon(icon) if python.is_string(column): self._icon[column] = icon else: self._pixmap[column] = None super(ItemView, self).setIcon(column, icon) self.update_icon()
def __init__(self, *args, **kwargs): QListView.__init__(self, *args, **kwargs) mixinview.ViewerViewWidgetMixin.__init__(self) self.setSpacing(5) self.setMouseTracking(True) self.setSelectionRectVisible(True) self.setViewMode(QListView.IconMode) self.setResizeMode(QListView.Adjust) self.setSelectionMode(QListView.ExtendedSelection) self.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff) self.setAcceptDrops(True) self.setDragEnabled(True) self.setDragDropMode(QAbstractItemView.DragDrop) self._tree_widget = None self._rubber_band = None self._rubber_band_start_pos = None self._rubber_band_color = QColor(Qt.white) self._custom_sort_order = list() self._drag = None self._drag_start_pos = None self._drag_start_index = None self._drop_enabled = True self.clicked.connect(self._on_index_clicked) self.doubleClicked.connect(self._on_index_double_clicked)