本文整理汇总了C++中QMimeData::text方法的典型用法代码示例。如果您正苦于以下问题:C++ QMimeData::text方法的具体用法?C++ QMimeData::text怎么用?C++ QMimeData::text使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QMimeData
的用法示例。
在下文中一共展示了QMimeData::text方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setUrls
void tst_QMimeData::setUrls() const
{
QMimeData mimeData;
QList<QUrl> shortUrlList;
QList<QUrl> longUrlList;
// set up
shortUrlList += QUrl("http://qt-project.org");
longUrlList = shortUrlList;
longUrlList += QUrl("http://www.google.com");
// verify initial state
QCOMPARE(mimeData.hasUrls(), false);
// set a few, verify
mimeData.setUrls(shortUrlList);
QCOMPARE(mimeData.urls(), shortUrlList);
QCOMPARE(mimeData.text(), QString("http://qt-project.org"));
// change them, verify
mimeData.setUrls(longUrlList);
QCOMPARE(mimeData.urls(), longUrlList);
QCOMPARE(mimeData.text(), QString("http://qt-project.org\nhttp://www.google.com\n"));
// clear, verify
mimeData.clear();
QCOMPARE(mimeData.hasUrls(), false);
QCOMPARE(mimeData.hasText(), false);
}
示例2: setText
void tst_QMimeData::setText() const
{
QMimeData mimeData;
// verify initial state
QCOMPARE(mimeData.text(), QLatin1String(""));
QVERIFY(mimeData.hasText() == false);
// set, verify
mimeData.setText("pirates");
QVERIFY(mimeData.hasText());
QCOMPARE(mimeData.text(), QLatin1String("pirates"));
QCOMPARE(mimeData.text().toLatin1(), mimeData.data("text/plain"));
// reset, verify
mimeData.setText("ninjas");
QVERIFY(mimeData.hasText());
QCOMPARE(mimeData.text(), QLatin1String("ninjas"));
QCOMPARE(mimeData.text().toLatin1(), mimeData.data("text/plain"));
// clear, verify
mimeData.clear();
QCOMPARE(mimeData.text(), QLatin1String(""));
QVERIFY(mimeData.hasText() == false);
}
示例3:
QDebug operator<<(QDebug d, const QMimeData &m)
{
QDebug nospace = d.nospace();
const QStringList formats = m.formats();
nospace << "QMimeData: " << formats.join(QStringLiteral(", ")) << '\n'
<< " Text=" << m.hasText() << " HTML=" << m.hasHtml()
<< " Color=" << m.hasColor() << " Image=" << m.hasImage()
<< " URLs=" << m.hasUrls() << '\n';
if (m.hasText())
nospace << " Text: '" << m.text() << "'\n";
if (m.hasHtml())
nospace << " HTML: '" << m.html() << "'\n";
if (m.hasColor())
nospace << " Color: " << qvariant_cast<QColor>(m.colorData()) << '\n';
if (m.hasImage())
nospace << " Image: " << qvariant_cast<QImage>(m.imageData()).size() << '\n';
if (m.hasUrls())
nospace << " URLs: " << m.urls() << '\n';
return d;
}
示例4: getTextHelper
QString PsiTextView::getTextHelper(bool html) const
{
PsiTextView *ptv = (PsiTextView *)this;
QTextCursor cursor = ptv->textCursor();
int position = ptv->verticalScrollBar()->value();
bool unselectAll = false;
if (!textCursor().hasSelection()) {
#if QT_VERSION == 0x040701
// workaround for crash when deleting last character with backspace (qt-4.7.1)
// http://bugreports.qt.nokia.com/browse/QTBUG-15857
QTextCursor tempCursor = QTextCursor(ptv->document());
tempCursor.movePosition(QTextCursor::Start);
ptv->setTextCursor(tempCursor);
#endif
ptv->selectAll();
unselectAll = true;
}
QMimeData *mime = createMimeDataFromSelection();
QString result;
if (html)
result = mime->html();
else
result = mime->text();
delete mime;
// we need to restore original position if selectAll()
// was called, because setTextCursor() (which is necessary
// to clear selection) will move vertical scroll bar
if (unselectAll) {
cursor.clearSelection();
ptv->setTextCursor(cursor);
ptv->verticalScrollBar()->setValue(position);
}
return result;
}
示例5: mousePressEvent
void PlayListW::mousePressEvent(QMouseEvent *event) {
QListWidget::mousePressEvent(event);
if ( event->button() == Qt::LeftButton ) {
QListWidgetItem *item = currentItem();
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData();
//Playlist Id, convoluted? indeed
QByteArray playlistba;
playlistba.append(item->text());
mimeData->setText(item->text());
mimeData->setData("application/playlist-id", playlistba);
drag->setMimeData(mimeData);
qDebug() << "Start Playlist Drag: " << mimeData->text()
<< " " << mimeData->data("application/playlist-id").toInt();
Qt::DropAction dropAction = drag->start(Qt::CopyAction); // [WTF]
}
}
示例6: startDrag
void FixedWidthTableView::startDrag(Qt::DropActions supportedActions)
{
QModelIndex item = currentIndex();
QModelIndexList list;
list.append(item);
QMimeData* mimeData = model()->mimeData(list);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
QPixmap pixmap = getDragPixmap(mimeData->text());
drag->setPixmap(pixmap);
QPoint hotpoint(pixmap.width()+10, pixmap.height()/2);
drag->setHotSpot(hotpoint);
if (drag->exec(Qt::CopyAction|Qt::MoveAction, Qt::CopyAction) == Qt::MoveAction)
{
// item moved
}
else
{
// item copied
}
}