Reimplement Qt method
766711
def contextMenuEvent(self, event):
        """"""
        self.menu.popup(event.globalPos())
        event.accept()
495506
def set_widgets(self):
        """"""
        self.tblFunctions1.horizontalHeader().setSectionResizeMode(
            QHeaderView.Stretch)
        self.tblFunctions1.verticalHeader().setSectionResizeMode(
            QHeaderView.Stretch)

        self.populate_function_table_1()
439552
def create(self):
        """"""
        self.idx_chan = QComboBox()
        self.idx_chan.activated.connect(self.display_window)

        self.idx_fig = QGraphicsView(self)
        self.idx_fig.scale(1, -1)

        layout = QVBoxLayout()
        layout.addWidget(self.idx_chan)
        layout.addWidget(self.idx_fig)
        self.setLayout(layout)

        self.resizeEvent(None)
363803
def _pyqt5():
    """"""

    import PyQt5 as module
    _setup(module, ["uic"])

    try:
        import sip
        Qt.QtCompat.wrapInstance = (
            lambda ptr, base=None: _wrapinstance(
                sip.wrapinstance, ptr, base)
        )
        Qt.QtCompat.getCppPointer = lambda object: \
            sip.unwrapinstance(object)

    except ImportError:
        pass  # Optional

    if hasattr(Qt, "_uic"):
        Qt.QtCompat.loadUi = _loadUi

    if hasattr(Qt, "_QtCore"):
        Qt.__binding_version__ = Qt._QtCore.PYQT_VERSION_STR
        Qt.__qt_version__ = Qt._QtCore.QT_VERSION_STR
        Qt.QtCompat.qInstallMessageHandler = _qInstallMessageHandler
        Qt.QtCompat.translate = Qt._QtCore.QCoreApplication.translate

    if hasattr(Qt, "_QtWidgets"):
        Qt.QtCompat.setSectionResizeMode = \
            Qt._QtWidgets.QHeaderView.setSectionResizeMode

    _reassign_misplaced_members("PyQt5")
    _build_compatibility_members('PyQt5')
1286578
def setup_ui(self, ):
        
        grid = QtGui.QGridLayout(self)
        grid.setContentsMargins(0, 0, 0, 0)
        self.setLayout(grid)
1131454
def set_widgets(self):
        """"""
        self.clear_further_steps()
        # Set widgets
        purpose = self.parent.step_kw_purpose.selected_purpose()
        self.lstSubcategories.clear()
        self.lblDescribeSubcategory.setText('')
        self.lblIconSubcategory.setPixmap(QPixmap())
        self.lblSelectSubcategory.setText(
            get_question_text('%s_question' % purpose['key']))
        for i in self.subcategories_for_layer():
            # noinspection PyTypeChecker
            item = QListWidgetItem(i['name'], self.lstSubcategories)
            # noinspection PyTypeChecker
            item.setData(QtCore.Qt.UserRole, i['key'])
            self.lstSubcategories.addItem(item)

        # Check if layer keywords are already assigned
        key = self.parent.step_kw_purpose.selected_purpose()['key']
        keyword = self.parent.get_existing_keyword(key)

        # Overwrite the keyword if it's KW mode embedded in IFCW mode
        if self.parent.parent_step:
            keyword = self.parent.get_parent_mode_constraints()[1]['key']

        # Set values based on existing keywords or parent mode
        if keyword:
            subcategories = []
            for index in range(self.lstSubcategories.count()):
                item = self.lstSubcategories.item(index)
                subcategories.append(item.data(QtCore.Qt.UserRole))
            if keyword in subcategories:
                self.lstSubcategories.setCurrentRow(
                    subcategories.index(keyword))

        self.auto_select_one_item(self.lstSubcategories)
425129
def event(self, event):
        
        if event.type() == QEvent.KeyPress:
            if (event.key() == Qt.Key_Tab or event.key() == Qt.Key_Space):
                text = self.text()
                cursor = self.cursorPosition()
                # fix to include in "undo/redo" history
                if cursor != 0 and text[cursor-1] == ' ':
                    text = text[:cursor-1] + ROW_SEPARATOR + ' ' +\
                        text[cursor:]
                else:
                    text = text[:cursor] + ' ' + text[cursor:]
                self.setCursorPosition(cursor)
                self.setText(text)
                self.setCursorPosition(cursor + 1)
                return False
        return QWidget.event(self, event)
430708
def __initialize_ui(self):
        

        self.__clear_button.setCursor(Qt.ArrowCursor)
        if self.__ui_clear_image and self.__ui_clear_clicked_image:
            pixmap = QPixmap(self.__ui_clear_image)
            clicked_pixmap = QPixmap(self.__ui_clear_clicked_image)
            self.__clear_button.setIcon(QIcon(pixmap))
            self.__clear_button.setMaximumSize(pixmap.size())

            # Signals / Slots.
            self.__clear_button.pressed.connect(functools.partial(self.__clear_button.setIcon, QIcon(clicked_pixmap)))
            self.__clear_button.released.connect(functools.partial(self.__clear_button.setIcon, QIcon(pixmap)))
        else:
            self.__clear_button.setText("Clear")

        self.__set_style_sheet()

        frame_width = self.style().pixelMetric(QStyle.PM_DefaultFrameWidth)
        self.setMinimumSize(
            max(self.minimumSizeHint().width(), self.__clear_button.sizeHint().height() + frame_width * 2),
            max(self.minimumSizeHint().height(), self.__clear_button.sizeHint().height() + frame_width * 2))

        self.__completer.setCaseSensitivity(Qt.CaseInsensitive)
        self.__completer.setCompletionMode(QCompleter.UnfilteredPopupCompletion)
        self.__completer.setMaxVisibleItems(self.__completer_visible_items_count)
415245
def _updateWidgets(self):
        
        row = 0
        model = self.tree.model()

        # Create path label
        nodePath = '' if self.rti is None else self.rti.nodePath
        pathItem = QtGui.QStandardItem(nodePath)
        pathItem.setToolTip(nodePath)
        pathItem.setEditable(False)
        if self.rti is not None:
            pathItem.setIcon(self.rti.decoration)
        model.setItem(row, 0, pathItem)

        self._deleteSpinBoxes(row)
        self._populateComboBoxes(row)
        self._createSpinBoxes(row)
        self._updateRtiInfo()

        self.tree.resizeColumnsToContents(startCol=self.COL_FIRST_COMBO)

        logger.debug("{} sigContentsChanged signal (_updateWidgets)"
                      .format("Blocked" if self.signalsBlocked() else "Emitting"))
        self.sigContentsChanged.emit(UpdateReason.RTI_CHANGED)
988781
def initialize():
    """"""
    # This doesn't create our QApplication, just holds a reference to
    # MAIN_APP, created above to show our splash screen as early as
    # possible
    app = qapplication()

    # --- Set application icon
    app.setWindowIcon(APP_ICON)

    #----Monkey patching QApplication
    class FakeQApplication(QApplication):
        """Spyder's fake QApplication"""
        def __init__(self, args):
            self = app  # analysis:ignore
        @staticmethod
        def exec_():
            """Do nothing because the Qt mainloop is already running"""
            pass
    from qtpy import QtWidgets
    QtWidgets.QApplication = FakeQApplication

    # ----Monkey patching sys.exit
    def fake_sys_exit(arg=[]):
        pass
    sys.exit = fake_sys_exit

    # ----Monkey patching sys.excepthook to avoid crashes in PyQt 5.5+
    if PYQT5:
        def spy_excepthook(type_, value, tback):
            sys.__excepthook__(type_, value, tback)
        sys.excepthook = spy_excepthook

    # Removing arguments from sys.argv as in standard Python interpreter
    sys.argv = ['']

    # Selecting Qt4 backend for Enthought Tool Suite (if installed)
    try:
        from enthought.etsconfig.api import ETSConfig
        ETSConfig.toolkit = 'qt4'
    except ImportError:
        pass

    return app
1339982
def mouseReleaseEvent(self, event):
        
        self.declaration.mouse_release_event(event)
        super(QtGraphicsView, self).mouseReleaseEvent(event)
671622
def mouseMoveEvent(self, event):
        
        self.declaration.mouse_move_event(event)
        super(QtGraphicsView, self).mouseMoveEvent(event)
807170
def mousePressEvent(self, event):
        
        self._moveItemStarted = False
        rect = QtCore.QRect(0, 0, 12, self.height())

        # drag the tab off
        if not self._locked and rect.contains(event.pos()):
            tabbar = self.parent()
            panel = tabbar.parent()

            index = tabbar.indexOf(self)
            view = panel.widget(index)
            pixmap = QtGui.QPixmap.grabWidget(view)

            drag = QtGui.QDrag(panel)
            data = QtCore.QMimeData()
            data.setData('x-application/xview/tabbed_view', QtCore.QByteArray(str(index)))
            drag.setMimeData(data)
            drag.setPixmap(pixmap)

            if not drag.exec_():
                cursor = QtGui.QCursor.pos()
                geom = self.window().geometry()
                if not geom.contains(cursor):
                    view.popout()

        # allow moving indexes around
        elif not self._locked and self.isActive():
            self._moveItemStarted = self.parent().count() > 1

        else:
            self.activate()

        super(XViewPanelItem, self).mousePressEvent(event)
1324155
def eventFilter(self, widget, event):
        """"""
        if event.type() == QEvent.KeyPress and event.key() == Qt.Key_Delete:
            index = self.view().currentIndex().row()
            if index >= EXTERNAL_PATHS:
                # Remove item and update the view.
                self.removeItem(index)
                self.showPopup()
                # Set the view selection so that it doesn't bounce around.
                new_index = min(self.count() - 1, index)
                new_index = 0 if new_index < EXTERNAL_PATHS else new_index
                self.view().setCurrentIndex(self.model().index(new_index, 0))
                self.setCurrentIndex(new_index)
            return True
        return QComboBox.eventFilter(self, widget, event)
421834
def createqtconf():
    """"""

    template = """[Paths]
Prefix = {path}
Binaries = {path}
"""

    import PyQt5

    exedir = os.path.dirname(sys.executable)
    qtpath = os.path.join(exedir, "qt.conf")
    pyqt5path = os.path.abspath(PyQt5.__file__)
    binpath = os.path.dirname(pyqt5path).replace("\\", "/")

    try:
        with open(qtpath, "w") as f:
            f.write(template.format(path=binpath))
    except:
        pass
1039706
def insertItem(self, index, item):
        """"""
        row = index.row()
        self.beginInsertRows(QtCore.QModelIndex(), row, row)
        self.model.insertRow(row)
        self.endInsertRows()
        self.model.overwriteParam(index.row(), item)
822148
def paintEvent(self, event):
        
        if not self.toPlainText() and not self.hasFocus() and self._placeholder:
            p = QtGui.QPainter(self.viewport())
            p.setClipping(False)
            col = self.palette().text().color()
            col.setAlpha(128)
            oldpen = p.pen()
            p.setPen(col)
            p.drawText(self.viewport().geometry(), QtCore.Qt.AlignLeft | QtCore.Qt.AlignTop, self._placeholder)
            p.setPen(oldpen)
        else:
            return super(JB_PlainTextEdit, self).paintEvent(event)