本文整理汇总了Python中PyQt4.Qt.QRect.contains方法的典型用法代码示例。如果您正苦于以下问题:Python QRect.contains方法的具体用法?Python QRect.contains怎么用?Python QRect.contains使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QRect
的用法示例。
在下文中一共展示了QRect.contains方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Declaration
# 需要导入模块: from PyQt4.Qt import QRect [as 别名]
# 或者: from PyQt4.Qt.QRect import contains [as 别名]
class Declaration(QWidget):
hyperlink_activated = pyqtSignal(object)
def __init__(self, html_name, data, is_first=False, parent=None):
QWidget.__init__(self, parent)
self.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Minimum)
self.data = data
self.is_first = is_first
self.html_name = html_name
self.do_layout()
self.setMouseTracking(True)
def do_layout(self):
fm = self.fontMetrics()
bounding_rect = lambda text: fm.boundingRect(0, 0, 10000, 10000, Cell.FLAGS, text)
line_spacing = 2
side_margin = Cell.SIDE_MARGIN
self.rows = []
ypos = line_spacing + (1 if self.is_first else 0)
if 'href' in self.data:
name = self.data['href']
if isinstance(name, list):
name = self.html_name
br1 = bounding_rect(name)
sel = self.data['selector'] or ''
if self.data['type'] == 'inline':
sel = 'style=""'
br2 = bounding_rect(sel)
self.hyperlink_rect = QRect(side_margin, ypos, br1.width(), br1.height())
self.rows.append([
Cell(name, self.hyperlink_rect, color_role=QPalette.Link),
Cell(sel, QRect(br1.right() + side_margin, ypos, br2.width(), br2.height()), right_align=True)
])
ypos += max(br1.height(), br2.height()) + 2 * line_spacing
for prop in self.data['properties']:
text = prop.name + ':\xa0'
br1 = bounding_rect(text)
vtext = prop.value + '\xa0' + ('!' if prop.important else '') + prop.important
br2 = bounding_rect(vtext)
self.rows.append([
Cell(text, QRect(side_margin, ypos, br1.width(), br1.height()), color_role=QPalette.LinkVisited, is_overriden=prop.is_overriden),
Cell(vtext, QRect(br1.right() + side_margin, ypos, br2.width(), br2.height()), swatch=prop.color, is_overriden=prop.is_overriden)
])
ypos += max(br1.height(), br2.height()) + line_spacing
self.height_hint = ypos + line_spacing
self.width_hint = max(row[-1].rect.right() + side_margin for row in self.rows) if self.rows else 0
def sizeHint(self):
return QSize(self.width_hint, self.height_hint)
def paintEvent(self, ev):
p = QPainter(self)
p.setClipRect(ev.rect())
palette = self.palette()
p.setPen(palette.color(QPalette.WindowText))
if not self.is_first:
p.drawLine(0, 0, self.width(), 0)
try:
for row in self.rows:
for cell in row:
p.save()
try:
cell.draw(p, self.width(), palette)
finally:
p.restore()
finally:
p.end()
def mouseMoveEvent(self, ev):
if hasattr(self, 'hyperlink_rect'):
pos = ev.pos()
hovering = self.hyperlink_rect.contains(pos)
self.update_hover(hovering)
cursor = Qt.ArrowCursor
for r, row in enumerate(self.rows):
for cell in row:
if cell.rect.contains(pos):
cursor = Qt.PointingHandCursor if cell.rect is self.hyperlink_rect else Qt.IBeamCursor
if r == 0:
break
if cursor != Qt.ArrowCursor:
break
self.setCursor(cursor)
return QWidget.mouseMoveEvent(self, ev)
def mousePressEvent(self, ev):
if hasattr(self, 'hyperlink_rect'):
pos = ev.pos()
if self.hyperlink_rect.contains(pos):
self.emit_hyperlink_activated()
return QWidget.mousePressEvent(self, ev)
def emit_hyperlink_activated(self):
dt = self.data['type']
data = {'type':dt, 'name':self.html_name, 'syntax':'html'}
if dt == 'inline': # style attribute
#.........这里部分代码省略.........