示例#1
0
def commandLineUrlArgument() -> QUrl:
    args = QCoreApplication.arguments()
    for arg in args[1:]:
        if not arg.startswith("_"):
            return QUrl.fromUserInput(arg)

    return QUrl("https://www.qt.io")
示例#2
0
def main():
    import sys

    app = QApplication(sys.argv)

    QQuickWindow.setDefaultAlphaBuffer(True)

    QCoreApplication.setApplicationName("Photosurface")
    QCoreApplication.setOrganizationName("QtProject")
    QCoreApplication.setApplicationVersion(__qt_version__)
    parser = QCommandLineParser()
    parser.setApplicationDescription("Qt Quick Demo - Photo Surface")
    parser.addHelpOption()
    parser.addVersionOption()
    parser.addPositionalArgument("directory", "The image directory or URL to show.")
    parser.process(app)

    initialUrl = QUrl()
    if parser.positionalArguments():
        initialUrl = QUrl.fromUserInput(
            parser.positionalArguments()[0], QDir.currentPath(), QUrl.AssumeLocalFile
        )
        if not initialUrl.isValid():
            print(
                'Invalid argument: "',
                parser.positionalArguments()[0],
                '": ',
                initialUrl.errorString(),
            )
            sys.exit(1)

    nameFilters = imageNameFilters()

    engine = QQmlApplicationEngine()
    context: QQmlContext = engine.rootContext()

    picturesLocationUrl = QUrl.fromLocalFile(QDir.homePath())
    picturesLocations = QStandardPaths.standardLocations(
        QStandardPaths.PicturesLocation
    )
    if picturesLocations:
        picturesLocationUrl = QUrl.fromLocalFile(picturesLocations[0])
        if not initialUrl and QDir(picturesLocations[0]).entryInfoList(
            nameFilters, QDir.Files
        ):
            initialUrl = picturesLocationUrl

    context.setContextProperty("contextPicturesLocation", picturesLocationUrl)
    context.setContextProperty("contextInitialUrl", initialUrl)
    context.setContextProperty("contextImageNameFilters", nameFilters)

    engine.load(QUrl("qrc:///photosurface.qml"))
    if not engine.rootObjects():
        sys.exit(-1)

    sys.exit(app.exec_())
示例#3
0
def main():
    import sys

    QCoreApplication.setOrganizationName("QtExamples")
    QCoreApplication.setAttribute(Qt.AA_EnableHighDpiScaling)

    app = QApplication(sys.argv)
    url = QUrl()

    if len(sys.argv) > 1:
        url = QUrl.fromUserInput(sys.argv[1])
    else:
        url = QUrl("http://www.google.com/ncr")

    browser = MainWindow(url)
    browser.resize(1024, 768)
    browser.show()

    sys.exit(app.exec_())
示例#4
0
 def handleUrlClicked(self):
     self.m_webview.load(QUrl.fromUserInput(self.m_urlLineEdit.text()))
示例#5
0
 def run(self) -> bool:
     self.m_page.load(QUrl.fromUserInput(self.m_inputPath))
     return QApplication.exec_()
示例#6
0
 def changeLocation(self):
     url = QUrl.fromUserInput(self.locationEdit.text())
     self.view.load(url)
     self.view.setFocus()