本文整理匯總了Python中Qt.QtWidgets.QApplication方法的典型用法代碼示例。如果您正苦於以下問題:Python QtWidgets.QApplication方法的具體用法?Python QtWidgets.QApplication怎麽用?Python QtWidgets.QApplication使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Qt.QtWidgets
的用法示例。
在下文中一共展示了QtWidgets.QApplication方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: run
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def run():
app = App()
def interrupt(*args):
""" Cleanly exit the application if a KeyboardInterrupt is detected.
"""
logger.info("KeyboardInterrupt")
app.onExit()
QtWidgets.QApplication.quit()
sys.exit(0)
# Allow Ctrl+C to kill the GUI, but first clean up any temp files we left lying around.
try:
signal.signal(signal.SIGINT, interrupt)
except ValueError as e:
logger.warning("You may not be able to kill this app via Ctrl-C: {}".format(e))
app.run()
示例2: test_load_ui_customwidget
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def test_load_ui_customwidget():
"""Tests to see if loadUi loads a custom widget properly"""
import sys
from Qt import QtWidgets, QtCompat
app = QtWidgets.QApplication(sys.argv)
win = QtWidgets.QMainWindow()
QtCompat.loadUi(self.ui_qcustomwidget, win)
# Ensure that the derived class was properly created
# and not the base class (in case of failure)
custom_class_name = getattr(win, "customwidget", None).__class__.__name__
excepted_class_name = CustomWidget(win).__class__.__name__
assert custom_class_name == excepted_class_name, \
"loadUi could not load custom widget to main window"
app.exit()
示例3: test_load_ui_invalidxml
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def test_load_ui_invalidxml():
"""Tests to see if loadUi successfully fails on invalid ui files"""
import sys
invalid_xml = os.path.join(self.tempdir, "invalid.ui")
with io.open(invalid_xml, "w", encoding="utf-8") as f:
f.write(u"""
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0" garbage
</ui>
""")
from xml.etree import ElementTree
from Qt import QtWidgets, QtCompat
app = QtWidgets.QApplication(sys.argv)
assert_raises(ElementTree.ParseError, QtCompat.loadUi, invalid_xml)
app.exit()
示例4: test_qtcompat_base_class
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def test_qtcompat_base_class():
"""Tests to ensure the QtCompat namespace object works as expected"""
import sys
import Qt
from Qt import QtWidgets
from Qt import QtCompat
app = QtWidgets.QApplication(sys.argv)
# suppress `local variable 'app' is assigned to but never used`
app
header = QtWidgets.QHeaderView(Qt.QtCore.Qt.Horizontal)
# Spot check compatibility functions
QtCompat.QHeaderView.setSectionsMovable(header, False)
assert QtCompat.QHeaderView.sectionsMovable(header) is False
QtCompat.QHeaderView.setSectionsMovable(header, True)
assert QtCompat.QHeaderView.sectionsMovable(header) is True
# Verify that the grab function actually generates a non-null image
button = QtWidgets.QPushButton('TestImage')
pixmap = QtCompat.QWidget.grab(button)
assert not pixmap.isNull()
示例5: test_wrapInstance
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def test_wrapInstance():
""".wrapInstance and .getCppPointer is identical across all bindings"""
from Qt import QtCompat, QtWidgets
app = QtWidgets.QApplication(sys.argv)
try:
button = QtWidgets.QPushButton("Hello world")
button.setObjectName("MySpecialButton")
pointer = QtCompat.getCppPointer(button)
widget = QtCompat.wrapInstance(long(pointer),
QtWidgets.QWidget)
assert isinstance(widget, QtWidgets.QWidget), widget
assert widget.objectName() == button.objectName()
# IMPORTANT: this differs across sip and shiboken.
if binding("PySide") or binding("PySide2"):
assert widget != button
else:
assert widget == button
finally:
app.exit()
示例6: test
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def test():
"""Example: QtCompat.loadUi with setup_ui wrapper"""
working_directory = os.path.dirname(__file__)
os.chdir(working_directory)
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
# Tests
assert isinstance(window, QtWidgets.QWidget)
assert isinstance(window.parent(), type(None))
assert isinstance(window.base_instance, QtWidgets.QWidget)
assert isinstance(window.lineEdit, QtWidgets.QWidget)
assert window.lineEdit.text() == ''
window.lineEdit.setText('Hello')
assert window.lineEdit.text() == 'Hello'
app.exit()
示例7: test
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def test():
"""Example: load_ui with custom uic.loadUi-like wrapper"""
working_directory = os.path.dirname(__file__)
os.chdir(working_directory)
app = QtWidgets.QApplication(sys.argv)
window = MainWindow()
# Tests
assert isinstance(window, QtWidgets.QWidget)
assert isinstance(window.parent(), type(None))
assert isinstance(window.base_instance, QtWidgets.QWidget)
assert isinstance(window.lineEdit, QtWidgets.QWidget)
assert window.lineEdit.text() == ''
window.lineEdit.setText('Hello')
assert window.lineEdit.text() == 'Hello'
app.exit()
示例8: main
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def main():
global debug
# Parse command line arguments
parser = argparse.ArgumentParser(
prog="qspectrumanalyzer",
description="Spectrum analyzer for multiple SDR platforms",
)
parser.add_argument("--debug", action="store_true",
help="detailed debugging messages")
parser.add_argument("--version", action="version",
version="%(prog)s {}".format(__version__))
args, unparsed_args = parser.parse_known_args()
debug = args.debug
try:
# Hide console window on Windows
if sys.platform == 'win32' and not debug:
from qspectrumanalyzer import windows
windows.set_attached_console_visible(False)
# Start PyQt application
app = QtWidgets.QApplication(sys.argv[:1] + unparsed_args)
app.setOrganizationName("QSpectrumAnalyzer")
app.setOrganizationDomain("qspectrumanalyzer.eutopia.cz")
app.setApplicationName("QSpectrumAnalyzer")
window = QSpectrumAnalyzerMainWindow()
sys.exit(app.exec_())
finally:
# Unhide console window on Windows (we don't want to leave zombies behind)
if sys.platform == 'win32' and not debug:
windows.set_attached_console_visible(True)
示例9: setOverrideCursor
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def setOverrideCursor(self, cursor=QtCore.Qt.WaitCursor):
""" Set the override cursor if it is not already set.
:Parameters:
cursor
Qt cursor
"""
if not QtWidgets.QApplication.overrideCursor():
QtWidgets.QApplication.setOverrideCursor(cursor)
示例10: restoreOverrideCursor
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def restoreOverrideCursor(self):
""" If an override cursor is currently set, restore the previous cursor.
"""
if QtWidgets.QApplication.overrideCursor():
QtWidgets.QApplication.restoreOverrideCursor()
示例11: copySelectionToClipboard
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def copySelectionToClipboard(self):
""" Store current selection to the middle mouse selection.
Doing this on selectionChanged signal instead of mouseReleaseEvent causes the following to be output in Qt5:
"QXcbClipboard: SelectionRequest too old"
For some reason, this isn't needed for QTextEdit but is for QTextBrowser?
"""
cursor = self.textCursor()
if cursor.hasSelection():
selection = cursor.selectedText().replace(u'\u2029', '\n')
clipboard = QtWidgets.QApplication.clipboard()
clipboard.setText(selection, clipboard.Selection)
示例12: main
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def main():
app = QApplication(sys.argv)
instance = PyFlow.instance(software="standalone")
if instance is not None:
app.setActiveWindow(instance)
instance.show()
try:
sys.exit(app.exec_())
except Exception as e:
print(e)
示例13: test_load_ui_returntype
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def test_load_ui_returntype():
"""load_ui returns an instance of QObject"""
import sys
from Qt import QtWidgets, QtCore, QtCompat
app = QtWidgets.QApplication(sys.argv)
obj = QtCompat.loadUi(self.ui_qwidget)
assert isinstance(obj, QtCore.QObject)
app.exit()
示例14: test_load_ui_baseinstance
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def test_load_ui_baseinstance():
"""Tests to see if the baseinstance loading loads a QWidget on properly"""
import sys
from Qt import QtWidgets, QtCompat
app = QtWidgets.QApplication(sys.argv)
win = QtWidgets.QWidget()
QtCompat.loadUi(self.ui_qwidget, win)
assert hasattr(win, 'lineEdit'), "loadUi could not load instance to win"
app.exit()
示例15: test_load_ui_signals
# 需要導入模塊: from Qt import QtWidgets [as 別名]
# 或者: from Qt.QtWidgets import QApplication [as 別名]
def test_load_ui_signals():
"""Tests to see if the baseinstance connects signals properly"""
import sys
from Qt import QtWidgets, QtCompat
app = QtWidgets.QApplication(sys.argv)
win = QtWidgets.QWidget()
QtCompat.loadUi(self.ui_qwidget, win)
win.lineEdit.setText('Hello')
assert str(win.label.text()) == 'Hello', "lineEdit signal did not fire"
app.exit()