本文整理汇总了Python中AnyQt.QtWidgets.QGraphicsView.setRenderHints方法的典型用法代码示例。如果您正苦于以下问题:Python QGraphicsView.setRenderHints方法的具体用法?Python QGraphicsView.setRenderHints怎么用?Python QGraphicsView.setRenderHints使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类AnyQt.QtWidgets.QGraphicsView
的用法示例。
在下文中一共展示了QGraphicsView.setRenderHints方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestItems
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsView [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsView import setRenderHints [as 别名]
class TestItems(QAppTestCase):
def setUp(self):
super().setUp()
self.scene = QGraphicsScene()
self.view = QGraphicsView(self.scene)
self.view.setRenderHints(
QPainter.Antialiasing |
QPainter.SmoothPixmapTransform |
QPainter.TextAntialiasing
)
self.view.resize(500, 300)
self.view.show()
def tearDown(self):
self.scene.clear()
self.scene.deleteLater()
self.view.deleteLater()
del self.scene
del self.view
super().tearDown()
示例2: TestItems
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsView [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsView import setRenderHints [as 别名]
class TestItems(unittest.TestCase):
def setUp(self):
import logging
from AnyQt.QtWidgets import \
QApplication, QGraphicsScene, QGraphicsView
from AnyQt.QtGui import QPainter
from AnyQt.QtCore import QTimer
logging.basicConfig()
self.app = QApplication([])
self.scene = QGraphicsScene()
self.view = QGraphicsView(self.scene)
self.view.setRenderHints(
QPainter.Antialiasing | \
QPainter.SmoothPixmapTransform | \
QPainter.TextAntialiasing
)
self.view.resize(500, 300)
self.view.show()
QTimer.singleShot(10000, self.app.exit)
def my_excepthook(*args):
sys.setrecursionlimit(1010)
traceback.print_exc(limit=4)
self._orig_excepthook = sys.excepthook
sys.excepthook = my_excepthook
self.singleShot = QTimer.singleShot
def tearDown(self):
self.scene.clear()
self.scene.deleteLater()
self.view.deleteLater()
del self.scene
del self.view
self.app.processEvents()
del self.app
sys.excepthook = self._orig_excepthook
示例3: OWQualityControl
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsView [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsView import setRenderHints [as 别名]
class OWQualityControl(widget.OWWidget):
name = "Quality Control"
description = "Experiment quality control"
icon = "../widgets/icons/QualityControl.svg"
priority = 5000
inputs = [("Experiment Data", Orange.data.Table, "set_data")]
outputs = []
DISTANCE_FUNCTIONS = [("Distance from Pearson correlation",
dist_pcorr),
("Euclidean distance",
dist_eucl),
("Distance from Spearman correlation",
dist_spearman)]
settingsHandler = SetContextHandler()
split_by_labels = settings.ContextSetting({})
sort_by_labels = settings.ContextSetting({})
selected_distance_index = settings.Setting(0)
def __init__(self, parent=None):
super().__init__(parent)
## Attributes
self.data = None
self.distances = None
self.groups = None
self.unique_pos = None
self.base_group_index = 0
## GUI
box = gui.widgetBox(self.controlArea, "Info")
self.info_box = gui.widgetLabel(box, "\n")
## Separate By box
box = gui.widgetBox(self.controlArea, "Separate By")
self.split_by_model = itemmodels.PyListModel(parent=self)
self.split_by_view = QListView()
self.split_by_view.setSelectionMode(QListView.ExtendedSelection)
self.split_by_view.setModel(self.split_by_model)
box.layout().addWidget(self.split_by_view)
self.split_by_view.selectionModel().selectionChanged.connect(
self.on_split_key_changed)
## Sort By box
box = gui.widgetBox(self.controlArea, "Sort By")
self.sort_by_model = itemmodels.PyListModel(parent=self)
self.sort_by_view = QListView()
self.sort_by_view.setSelectionMode(QListView.ExtendedSelection)
self.sort_by_view.setModel(self.sort_by_model)
box.layout().addWidget(self.sort_by_view)
self.sort_by_view.selectionModel().selectionChanged.connect(
self.on_sort_key_changed)
## Distance box
box = gui.widgetBox(self.controlArea, "Distance Measure")
gui.comboBox(box, self, "selected_distance_index",
items=[name for name, _ in self.DISTANCE_FUNCTIONS],
callback=self.on_distance_measure_changed)
self.scene = QGraphicsScene()
self.scene_view = QGraphicsView(self.scene)
self.scene_view.setRenderHints(QPainter.Antialiasing)
self.scene_view.setAlignment(Qt.AlignLeft | Qt.AlignVCenter)
self.mainArea.layout().addWidget(self.scene_view)
self.scene_view.installEventFilter(self)
self._disable_updates = False
self._cached_distances = {}
self._base_index_hints = {}
self.main_widget = None
self.resize(800, 600)
def clear(self):
"""Clear the widget state."""
self.data = None
self.distances = None
self.groups = None
self.unique_pos = None
with disable_updates(self):
self.split_by_model[:] = []
self.sort_by_model[:] = []
self.main_widget = None
self.scene.clear()
self.info_box.setText("\n")
self._cached_distances = {}
def set_data(self, data=None):
"""Set input experiment data."""
self.closeContext()
self.clear()
#.........这里部分代码省略.........
示例4: OWBoxPlot
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsView [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsView import setRenderHints [as 别名]
#.........这里部分代码省略.........
sizePolicy=(QSizePolicy.Minimum, QSizePolicy.Maximum),
addSpace=False)
gui.checkBox(self.display_box, self, "show_annotations", "Annotate",
callback=self.display_changed)
self.compare_rb = gui.radioButtonsInBox(
self.display_box, self, 'compare',
btnLabels=["No comparison", "Compare medians", "Compare means"],
callback=self.layout_changed)
# The vertical size policy is needed to let only the list views expand
self.stretching_box = box = gui.vBox(
self.controlArea, box="Display",
sizePolicy=(QSizePolicy.Minimum, QSizePolicy.Fixed))
self.stretching_box.sizeHint = self.display_box.sizeHint
gui.checkBox(
box, self, 'stretched', "Stretch bars",
callback=self.display_changed)
gui.checkBox(
box, self, 'show_labels', "Show box labels",
callback=self.display_changed)
self.sort_cb = gui.checkBox(
box, self, 'sort_freqs', "Sort by subgroup frequencies",
callback=self.display_changed)
gui.rubber(box)
gui.auto_commit(self.controlArea, self, "auto_commit",
"Send Selection", "Send Automatically")
gui.vBox(self.mainArea, addSpace=True)
self.box_scene = QGraphicsScene()
self.box_scene.selectionChanged.connect(self.commit)
self.box_view = QGraphicsView(self.box_scene)
self.box_view.setRenderHints(QPainter.Antialiasing |
QPainter.TextAntialiasing |
QPainter.SmoothPixmapTransform)
self.box_view.viewport().installEventFilter(self)
self.mainArea.layout().addWidget(self.box_view)
e = gui.hBox(self.mainArea, addSpace=False)
self.infot1 = gui.widgetLabel(e, "<center>No test results.</center>")
self.mainArea.setMinimumWidth(300)
self.stats = self.dist = self.conts = []
self.is_continuous = False
self.update_display_box()
def sizeHint(self):
return QSize(900, 500)
def eventFilter(self, obj, event):
if obj is self.box_view.viewport() and \
event.type() == QEvent.Resize:
self.layout_changed()
return super().eventFilter(obj, event)
def reset_attrs(self, domain):
self.attrs[:] = [
var for var in chain(
domain.class_vars, domain.metas, domain.attributes)
if var.is_primitive()]
# noinspection PyTypeChecker
示例5: TestScene
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsView [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsView import setRenderHints [as 别名]
class TestScene(QAppTestCase):
def setUp(self):
QAppTestCase.setUp(self)
self.scene = CanvasScene()
self.view = QGraphicsView(self.scene)
self.view.setRenderHints(QPainter.Antialiasing | \
QPainter.TextAntialiasing)
self.view.show()
self.view.resize(400, 300)
def test_scene(self):
"""Test basic scene functionality.
"""
file_desc, disc_desc, bayes_desc = self.widget_desc()
file_item = items.NodeItem(file_desc)
disc_item = items.NodeItem(disc_desc)
bayes_item = items.NodeItem(bayes_desc)
file_item = self.scene.add_node_item(file_item)
disc_item = self.scene.add_node_item(disc_item)
bayes_item = self.scene.add_node_item(bayes_item)
# Remove a node
self.scene.remove_node_item(bayes_item)
self.assertSequenceEqual(self.scene.node_items(),
[file_item, disc_item])
# And add it again
self.scene.add_node_item(bayes_item)
self.assertSequenceEqual(self.scene.node_items(),
[file_item, disc_item, bayes_item])
# Adding the same item again should raise an exception
with self.assertRaises(ValueError):
self.scene.add_node_item(bayes_item)
# Add links
link1 = self.scene.new_link_item(file_item, "Data", disc_item, "Data")
link2 = self.scene.new_link_item(disc_item, "Data", bayes_item, "Data")
link1a = self.scene.add_link_item(link1)
link2a = self.scene.add_link_item(link2)
self.assertEqual(link1, link1a)
self.assertEqual(link2, link2a)
self.assertSequenceEqual(self.scene.link_items(), [link1, link2])
# Remove links
self.scene.remove_link_item(link2)
self.scene.remove_link_item(link1)
self.assertSequenceEqual(self.scene.link_items(), [])
self.assertTrue(link1.sourceItem is None and link1.sinkItem is None)
self.assertTrue(link2.sourceItem is None and link2.sinkItem is None)
self.assertSequenceEqual(file_item.outputAnchors(), [])
self.assertSequenceEqual(disc_item.inputAnchors(), [])
self.assertSequenceEqual(disc_item.outputAnchors(), [])
self.assertSequenceEqual(bayes_item.outputAnchors(), [])
# And add one link again
link1 = self.scene.new_link_item(file_item, "Data", disc_item, "Data")
link1 = self.scene.add_link_item(link1)
self.assertSequenceEqual(self.scene.link_items(), [link1])
self.assertTrue(file_item.outputAnchors())
self.assertTrue(disc_item.inputAnchors())
self.app.exec_()
def test_scene_with_scheme(self):
"""Test scene through modifying the scheme.
"""
test_scheme = scheme.Scheme()
self.scene.set_scheme(test_scheme)
node_items = []
link_items = []
self.scene.node_item_added.connect(node_items.append)
self.scene.node_item_removed.connect(node_items.remove)
self.scene.link_item_added.connect(link_items.append)
self.scene.link_item_removed.connect(link_items.remove)
file_desc, disc_desc, bayes_desc = self.widget_desc()
file_node = scheme.SchemeNode(file_desc)
disc_node = scheme.SchemeNode(disc_desc)
bayes_node = scheme.SchemeNode(bayes_desc)
nodes = [file_node, disc_node, bayes_node]
test_scheme.add_node(file_node)
test_scheme.add_node(disc_node)
test_scheme.add_node(bayes_node)
self.assertTrue(len(self.scene.node_items()) == 3)
self.assertSequenceEqual(self.scene.node_items(), node_items)
for node, item in zip(nodes, node_items):
self.assertIs(item, self.scene.item_for_node(node))
#.........这里部分代码省略.........
示例6: OWPieChart
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsView [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsView import setRenderHints [as 别名]
class OWPieChart(widget.OWWidget):
name = "Pie Chart"
description = "Make fun of Pie Charts."
icon = "icons/PieChart.svg"
priority = 100
class Inputs:
data = Input("Data", Orange.data.Table)
settingsHandler = DomainContextHandler()
attribute = ContextSetting(None)
split_var = ContextSetting(None)
explode = Setting(False)
graph_name = "scene"
def __init__(self):
super().__init__()
self.dataset = None
self.attrs = DomainModel(
valid_types=Orange.data.DiscreteVariable, separators=False)
cb = gui.comboBox(
self.controlArea, self, "attribute", box=True,
model=self.attrs, callback=self.update_scene, contentsLength=12)
grid = QGridLayout()
self.legend = gui.widgetBox(gui.indentedBox(cb.box), orientation=grid)
grid.setColumnStretch(1, 1)
grid.setHorizontalSpacing(6)
self.legend_items = []
self.split_vars = DomainModel(
valid_types=Orange.data.DiscreteVariable, separators=False,
placeholder="None", )
gui.comboBox(
self.controlArea, self, "split_var", box="Split by",
model=self.split_vars, callback=self.update_scene)
gui.checkBox(
self.controlArea, self, "explode", "Explode pies", box=True,
callback=self.update_scene)
gui.rubber(self.controlArea)
gui.widgetLabel(
gui.hBox(self.controlArea, box=True),
"The aim of this widget is to\n"
"demonstrate that pie charts are\n"
"a terrible visualization. Please\n"
"don't use it for any other purpose.")
self.scene = QGraphicsScene()
self.view = QGraphicsView(self.scene)
self.view.setRenderHints(
QPainter.Antialiasing | QPainter.TextAntialiasing |
QPainter.SmoothPixmapTransform)
self.mainArea.layout().addWidget(self.view)
self.mainArea.setMinimumWidth(600)
def sizeHint(self):
return QSize(200, 150) # Horizontal size is regulated by mainArea
@Inputs.data
def set_data(self, dataset):
if dataset is not None and (
not bool(dataset) or not len(dataset.domain)):
dataset = None
self.closeContext()
self.dataset = dataset
self.attribute = None
self.split_var = None
domain = dataset.domain if dataset is not None else None
self.attrs.set_domain(domain)
self.split_vars.set_domain(domain)
if dataset is not None:
self.select_default_variables(domain)
self.openContext(self.dataset)
self.update_scene()
def select_default_variables(self, domain):
if len(self.attrs) > len(domain.class_vars):
first_attr = self.split_vars[len(domain.class_vars)]
else:
first_attr = None
if len(self.attrs):
self.attribute, self.split_var = self.attrs[0], first_attr
else:
self.attribute, self.split_var = self.split_var, None
def update_scene(self):
self.scene.clear()
if self.dataset is None or self.attribute is None:
return
dists, labels = self.compute_box_data()
colors = self.attribute.colors
for x, (dist, label) in enumerate(zip(dists, labels)):
self.pie_chart(SCALE * x, 0, 0.8 * SCALE, dist, colors)
self.pie_label(SCALE * x, 0, label)
self.update_legend(
[QColor(*col) for col in colors], self.attribute.values)
self.view.centerOn(SCALE * len(dists) / 2, 0)
def update_legend(self, colors, labels):
layout = self.legend.layout()
while self.legend_items:
#.........这里部分代码省略.........
示例7: TestScene
# 需要导入模块: from AnyQt.QtWidgets import QGraphicsView [as 别名]
# 或者: from AnyQt.QtWidgets.QGraphicsView import setRenderHints [as 别名]
class TestScene(QAppTestCase):
def setUp(self):
super().setUp()
self.scene = CanvasScene()
self.view = QGraphicsView(self.scene)
self.view.setRenderHints(QPainter.Antialiasing |
QPainter.TextAntialiasing)
self.view.show()
self.view.resize(400, 300)
def tearDown(self):
self.scene.clear()
self.view.deleteLater()
self.scene.deleteLater()
del self.view
del self.scene
super().tearDown()
def test_scene(self):
"""Test basic scene functionality.
"""
one_desc, negate_desc, cons_desc = self.widget_desc()
one_item = items.NodeItem(one_desc)
negate_item = items.NodeItem(negate_desc)
cons_item = items.NodeItem(cons_desc)
one_item = self.scene.add_node_item(one_item)
negate_item = self.scene.add_node_item(negate_item)
cons_item = self.scene.add_node_item(cons_item)
# Remove a node
self.scene.remove_node_item(cons_item)
self.assertSequenceEqual(self.scene.node_items(),
[one_item, negate_item])
# And add it again
self.scene.add_node_item(cons_item)
self.assertSequenceEqual(self.scene.node_items(),
[one_item, negate_item, cons_item])
# Adding the same item again should raise an exception
with self.assertRaises(ValueError):
self.scene.add_node_item(cons_item)
# Add links
link1 = self.scene.new_link_item(
one_item, "value", negate_item, "value")
link2 = self.scene.new_link_item(
negate_item, "result", cons_item, "first")
link1a = self.scene.add_link_item(link1)
link2a = self.scene.add_link_item(link2)
self.assertEqual(link1, link1a)
self.assertEqual(link2, link2a)
self.assertSequenceEqual(self.scene.link_items(), [link1, link2])
# Remove links
self.scene.remove_link_item(link2)
self.scene.remove_link_item(link1)
self.assertSequenceEqual(self.scene.link_items(), [])
self.assertTrue(link1.sourceItem is None and link1.sinkItem is None)
self.assertTrue(link2.sourceItem is None and link2.sinkItem is None)
self.assertSequenceEqual(one_item.outputAnchors(), [])
self.assertSequenceEqual(negate_item.inputAnchors(), [])
self.assertSequenceEqual(negate_item.outputAnchors(), [])
self.assertSequenceEqual(cons_item.outputAnchors(), [])
# And add one link again
link1 = self.scene.new_link_item(
one_item, "value", negate_item, "value")
link1 = self.scene.add_link_item(link1)
self.assertSequenceEqual(self.scene.link_items(), [link1])
self.assertTrue(one_item.outputAnchors())
self.assertTrue(negate_item.inputAnchors())
self.app.exec_()
def test_scene_with_scheme(self):
"""Test scene through modifying the scheme.
"""
test_scheme = scheme.Scheme()
self.scene.set_scheme(test_scheme)
node_items = []
link_items = []
self.scene.node_item_added.connect(node_items.append)
self.scene.node_item_removed.connect(node_items.remove)
self.scene.link_item_added.connect(link_items.append)
self.scene.link_item_removed.connect(link_items.remove)
one_desc, negate_desc, cons_desc = self.widget_desc()
one_node = scheme.SchemeNode(one_desc)
negate_node = scheme.SchemeNode(negate_desc)
cons_node = scheme.SchemeNode(cons_desc)
#.........这里部分代码省略.........