本文整理汇总了Python中PyQt4.Qt.QMimeData.setText方法的典型用法代码示例。如果您正苦于以下问题:Python QMimeData.setText方法的具体用法?Python QMimeData.setText怎么用?Python QMimeData.setText使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.Qt.QMimeData
的用法示例。
在下文中一共展示了QMimeData.setText方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: selection_changed
# 需要导入模块: from PyQt4.Qt import QMimeData [as 别名]
# 或者: from PyQt4.Qt.QMimeData import setText [as 别名]
def selection_changed(self):
# Workaround Qt replacing nbsp with normal spaces on copy
clipboard = QApplication.clipboard()
if clipboard.supportsSelection() and self.textCursor().hasSelection():
md = QMimeData()
md.setText(self.selected_text)
clipboard.setMimeData(md, clipboard.Selection)
示例2: copy
# 需要导入模块: from PyQt4.Qt import QMimeData [as 别名]
# 或者: from PyQt4.Qt.QMimeData import setText [as 别名]
def copy(self):
# Workaround Qt replacing nbsp with normal spaces on copy
c = self.textCursor()
if not c.hasSelection():
return
md = QMimeData()
md.setText(self.selected_text)
QApplication.clipboard().setMimeData(md)
示例3: mouseMoveEvent
# 需要导入模块: from PyQt4.Qt import QMimeData [as 别名]
# 或者: from PyQt4.Qt.QMimeData import setText [as 别名]
def mouseMoveEvent(self, event):
if self.drag is not None:
QTreeView.mouseMoveEvent(self, event)
return
if ((event.globalPos() - self.mouse_press_qpoint).manhattanLength()
< QApplication.startDragDistance()):
return
#
# starting a drag
# [logic bug, after bruce change 070507: should not do this
# if we already started dragging out a selection. How can we tell?
# Only by whether the initial press had eventInRect, I think
# (not yet recorded), or at least, the initial move (#e could record here).]
#
index = self.indexAt(event.pos())
sellst = self.selectedList() # bruce 070507 move earlier
DEBUG2 = True
if index.isValid():
thisnode = index.internalPointer().node
#bruce 070507 bring in some code from modelTreeGui.py
alreadySelected = (thisnode in sellst)
item = index.internalPointer()
rect = self.visualRect(index)
if DEBUG2:
print "visualRect coords",rect.left(), rect.right(), rect.top(), rect.bottom()
qfm = QFontMetrics(QLineEdit(self).font())
rect.setWidth(qfm.width(item.node.name) + _ICONSIZE[0] + 4)
if DEBUG2:
print "visualRect coords, modified:",rect.left(), rect.right(), rect.top(), rect.bottom()
# looks like icon and text, a bit taller than text (guesses)
eventInRect = rect.contains(event.pos())
if DEBUG2:
print "valid index: eventInRect = %r, item = %r, index = %r, alreadySelected = %r" % \
(eventInRect, item, index, alreadySelected)#######
else:
thisnode = item = None
alreadySelected = eventInRect = False
if not eventInRect:
# nothing to drag, but [bruce 070507] let super handle it (for dragging over nodes to select)
self.drag_is_not_DND = True ### not yet used
QTreeView.mouseMoveEvent(self, event)
return
if thisnode in sellst:
# if dragging something selected, drag along all other selected ones
dragged_nodes = sellst
else:
# if dragging something unselected, ignore any selected ones
dragged_nodes = [ thisnode ]
qdrag = QDrag(self)
drag_type = 'move' # how do I decide between 'move' and 'copy'?
self.drag = (dragged_nodes, drag_type, qdrag)
mimedata = QMimeData()
mimedata.setText("need a string here for a valid mimetype")
qdrag.setMimeData(mimedata)
display_prefs = { }
pixmap = dragged_nodes[0].node_icon(display_prefs)
qdrag.setPixmap(pixmap)
qdrag.setHotSpot(QPoint(-8, 8))
qdrag.start()