本文整理汇总了Python中PyQt4.QtCore.QMimeData.setData方法的典型用法代码示例。如果您正苦于以下问题:Python QMimeData.setData方法的具体用法?Python QMimeData.setData怎么用?Python QMimeData.setData使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PyQt4.QtCore.QMimeData
的用法示例。
在下文中一共展示了QMimeData.setData方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_dropping_the_data_emits_the_signal
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def test_dropping_the_data_emits_the_signal(self):
mw = self._get_one()
self.assertEqual(mw.supportedDropActions(),
Qt.CopyAction)
self.assertIn('application/vnd.re-eat.recipe', mw.mimeTypes())
assert mw.viewport().acceptDrops()
mw.recipeAdded = DummySignal()
mimeData = QMimeData()
encodedData = QByteArray()
stream = QDataStream(encodedData, QIODevice.WriteOnly)
stream.writeInt(1)
stream.writeInt(2)
mimeData.setData('application/vnd.re-eat.recipe', encodedData)
mw.dropMimeData(0, mimeData, Qt.CopyAction)
self.assertListEqual(mw.recipeAdded.received,
[(1, mw.date, mw.index),
(2, mw.date, mw.index)])
mw.recipeMoved = DummySignal()
mimeData = QMimeData()
encodedData = QByteArray()
stream = QDataStream(encodedData, QIODevice.WriteOnly)
stream.writeInt(42)
stream.writeQVariant(datetime.date.today())
stream.writeInt(2)
mimeData.setData('application/vnd.re-eat.meal_recipe', encodedData)
mw.dropMimeData(0, mimeData, Qt.CopyAction)
self.assertListEqual(mw.recipeMoved.received,
[(42, datetime.date.today(), 2, mw.date, mw.index)])
示例2: copy
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def copy(self):
"""Copy to the clipboard"""
data = QMimeData()
text = "\n".join([cursor.selectedText() for cursor in self.cursors()])
data.setText(text)
data.setData(self.MIME_TYPE, text.encode("utf8"))
QApplication.clipboard().setMimeData(data)
示例3: mimeData
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def mimeData(self, indexes):
items = (index.internalPointer() for index in indexes if index.isValid())
uri_list = self._getURIs(items)
uri_list.sort()
data = QMimeData()
data.setData('mpd/uri', pickle.dumps(uri_list))
return data
示例4: _newListDropEvent
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def _newListDropEvent(self, event):
if event.provides('mpd/uri'):
event.accept()
parent = self._newList()
data = QMimeData()
data.setData('mpd/uri', event.mimeData().data('mpd/uri'))
def disconnect(item, row=-1, column=-1):
if parent.row() == row:
self.disconnect(self.playlistList.itemDelegate(parent),
SIGNAL('commitData(QWidget *)'),
addSongs)
self.disconnect(self.playlistModel,
SIGNAL('rowsAboutToBeRemoved(const QModelIndex &, int , int)'),
disconnect)
def addSongs(editor, data=data):
# Make sure to disconnect from the signals.
if parent.data(Qt.DisplayRole):
disconnect(None, parent.row())
self.playlistModel.dropMimeData(data, Qt.CopyAction, 0, 0, parent)
self.connect(self.playlistList.itemDelegate(parent),
SIGNAL('commitData(QWidget *)'),
addSongs)
self.connect(self.playlistModel,
SIGNAL('rowsAboutToBeRemoved(const QModelIndex &, int , int)'),
disconnect)
示例5: mimeData
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def mimeData(self, indexes):
nodes = dedupe(index.internalPointer() for index in indexes)
paths = [str(self.name + node.ref.path) for node in nodes]
data = '\n'.join(paths).encode('utf-8')
mimeData = QMimeData()
mimeData.setData(MIME_PATHS, QByteArray(data))
return mimeData
示例6: __onDragStarted
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def __onDragStarted(self, index):
desc = index.data(QtWidgetRegistry.WIDGET_DESC_ROLE)
icon = index.data(Qt.DecorationRole)
drag_data = QMimeData()
drag_data.setData(
"application/vnv.orange-canvas.registry.qualified-name",
desc.qualified_name
)
drag = QDrag(self)
drag.setPixmap(icon.pixmap(38))
drag.setMimeData(drag_data)
# TODO: Should animate (accept) hide.
self.hide()
# When a drag is started and the menu hidden the item's tool tip
# can still show for a short time UNDER the cursor preventing a
# drop.
viewport = self.__menu.view().viewport()
filter = ToolTipEventFilter()
viewport.installEventFilter(filter)
drag.exec_(Qt.CopyAction)
viewport.removeEventFilter(filter)
示例7: mimeData
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def mimeData(self, indexes):
if len(indexes) == 1:
item = indexes[0].internalPointer()
d = QMimeData()
d.setData(variable.MIME_TYPE, item.uniqueName)
return d
else:
return None
示例8: startDrag
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def startDrag(self, dropAction):
# create mime data object
mime = QMimeData()
mime.setData('text/xml', '???')
# start drag
drag = QDrag(self)
drag.setMimeData(mime)
drag.start(Qt.CopyAction | Qt.CopyAction)
示例9: mimeData
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def mimeData(self, indexes ):
"""See QAbstractItemModel documentation"""
if len(indexes) != 1:
return 0
data = QMimeData()
data.setData( self.mimeTypes()[0], QByteArray.number( indexes[0].row() ) )
return data
示例10: mimeData
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def mimeData(self, indexes):
sortedIndexes = sorted([index for index in indexes
if index.isValid()], key=lambda index: index.row())
encodedData = '\n'.join(self.data(index, Qt.DisplayRole)
for index in sortedIndexes)
mimeData = QMimeData()
mimeData.setData(self.Mimetype, encodedData)
return mimeData
示例11: mimeData
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def mimeData(self, indexes):
if len(indexes) == 0:
return 0
index = indexes[0]
card = self.list[index.row()]
string = pickle.dumps(card)
result = QMimeData()
result.setData('application/x-QCard', string)
return result
示例12: mimeData
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def mimeData(self, indexes):
albums = (self._albums[index.row()] for index in indexes if index.isValid())
uri_list = []
for album in albums:
uri_list.extend(song.file.absolute for song in album.songs)
uri_list.sort()
data = QMimeData()
data.setData('mpd/uri', pickle.dumps(uri_list))
return data
示例13: mimeData
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def mimeData(self, items):
mimeData = QMimeData()
encodedData = QByteArray()
stream = QDataStream(encodedData, QIODevice.WriteOnly)
for item in items:
id = item.data(Qt.UserRole)
stream.writeInt(id)
mimeData.setData('application/vnd.re-eat.recipe', encodedData)
return mimeData
示例14: mimeData
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def mimeData(self, indexes):
''' Encodes the data for the items in indexes in MIME types for drag and drop actions. '''
row_list = [index.row() for index in indexes]
row_list.sort()
if len(row_list) == 0:
return 0
data = QMimeData()
data.setData('mpd/playqueue_id', pickle.dumps([(row, int(self._songs[row].id)) for row in row_list]))
data.setData('mpd/uri', pickle.dumps([self._songs[row].file.absolute for row in row_list]))
return data
示例15: dataCollector
# 需要导入模块: from PyQt4.QtCore import QMimeData [as 别名]
# 或者: from PyQt4.QtCore.QMimeData import setData [as 别名]
def dataCollector( tree, items ):
data = QMimeData()
actions = []
for item in items:
actions.append(str(qt.unwrapVariant(item.data(0, Qt.UserRole))))
actionstr = ','.join(actions)
data.setData('application/x-actions', QByteArray(actionstr))
return data