当前位置: 首页>>代码示例>>Python>>正文


Python QWebView.setContextMenuPolicy方法代码示例

本文整理汇总了Python中PySide.QtWebKit.QWebView.setContextMenuPolicy方法的典型用法代码示例。如果您正苦于以下问题:Python QWebView.setContextMenuPolicy方法的具体用法?Python QWebView.setContextMenuPolicy怎么用?Python QWebView.setContextMenuPolicy使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PySide.QtWebKit.QWebView的用法示例。


在下文中一共展示了QWebView.setContextMenuPolicy方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: HTMLViewer

# 需要导入模块: from PySide.QtWebKit import QWebView [as 别名]
# 或者: from PySide.QtWebKit.QWebView import setContextMenuPolicy [as 别名]
class HTMLViewer(QtGui.QWidget):
    def __init__(self, parent=None):
        super(HTMLViewer, self).__init__(parent)

        self.view = QWebView(self)
        layout = QtGui.QVBoxLayout(self)
        layout.setSpacing(0)
        layout.setContentsMargins(0, 0, 0, 0)
        layout.addWidget(self.view)

        # Create ContextMenu
        context_menu = QtGui.QMenu(self.view)
        def open_context_menu(point):
            context_menu.exec_(self.view.mapToGlobal(point))
        self.view.setContextMenuPolicy(QtCore.Qt.CustomContextMenu)
        self.view.customContextMenuRequested.connect(open_context_menu)

        action = QtGui.QAction('&Back', self,
                shortcut=QtGui.QKeySequence.Back,
                statusTip="Click to go back",
                triggered=self.view.back)
        action.setShortcut('Backspace')
        context_menu.addAction(action)

        action = QtGui.QAction('&Forward', self,
                shortcut=QtGui.QKeySequence.Forward,
                statusTip="Click to go forward",
                triggered=self.view.forward)
        action.setShortcut('Shift + Backspace')
        context_menu.addAction(action)

        action = QtGui.QAction('&Reload', self,
                shortcut=QtGui.QKeySequence.Refresh,
                statusTip="Click to refresh",
                triggered=self.view.reload)
        context_menu.addAction(action)
        context_menu.addSeparator()

        action = QtGui.QAction('&Print', self,
                shortcut=QtGui.QKeySequence.Print,
                statusTip="Click to print",
                triggered=self.print_)
        context_menu.addAction(action)
        
    def contextMenuEvent(self, event):
        self.context_menu.exec_(event.globalPos())

    def print_(self):
        printer = QtGui.QPrinter()
        printer_dialog = QtGui.QPrintDialog(printer, self.view)
        if printer_dialog.exec_() != QtGui.QDialog.Accepted:
            # do nothing
            return
        # printout the view with selected printer
        self.view.print_(printer)

    # --- slots
    @QtCore.Slot(unicode)
    def update(self, value):
        # save vertical/horizontal scrollbar value
        m = self.view.page().mainFrame()
        v = m.scrollBarValue(QtCore.Qt.Vertical)
        h = m.scrollBarValue(QtCore.Qt.Horizontal)
        # set new HTML (value should be unicode)
        self.view.setHtml(value)
        # update vertical/horizontal scrollbar value
        m = self.view.page().mainFrame()
        m.setScrollBarValue(QtCore.Qt.Vertical, v)
        m.setScrollBarValue(QtCore.Qt.Horizontal, h)
开发者ID:guyomes,项目名称:Shareboard,代码行数:71,代码来源:viewer.py

示例2: QApplication

# 需要导入模块: from PySide.QtWebKit import QWebView [as 别名]
# 或者: from PySide.QtWebKit.QWebView import setContextMenuPolicy [as 别名]
#!/usr/bin/env python

import sys, os
from PySide.QtCore import QObject, Slot, Property, QUrl, QSize, Qt
from PySide.QtGui import QApplication, QDesktopServices
from PySide.QtNetwork import QNetworkAccessManager, QNetworkRequest, QNetworkReply
from PySide.QtWebKit import QWebView, QWebInspector, QWebPage, QWebSettings



app = QApplication(sys.argv)
wv = QWebView()

wv.setContextMenuPolicy(Qt.NoContextMenu)

page = wv.page()
mainFrame = page.mainFrame()

inspector = QWebInspector()
inspector.setPage(page)

class WebStoryNetworkAccessManager(QNetworkAccessManager):
    def __init__(self, parent=None):
        super(WebStoryNetworkAccessManager, self).__init__(parent)
        self.allowedUrls = set()
        self.allowedHosts = set()
    
    def addAllowedUrl(self, url):
        self.allowedUrls.add(url)
    
    def addAllowedHost(self, host):
开发者ID:jsteinbeck,项目名称:WebStory-Engine-LC,代码行数:33,代码来源:wse.py


注:本文中的PySide.QtWebKit.QWebView.setContextMenuPolicy方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。