本文整理汇总了C++中DragLabel类的典型用法代码示例。如果您正苦于以下问题:C++ DragLabel类的具体用法?C++ DragLabel怎么用?C++ DragLabel使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DragLabel类的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: foreach
void DragWidget::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasText()) {
const QMimeData *mime = event->mimeData();
QStringList pieces = mime->text().split(QRegExp("\\s+"),
QString::SkipEmptyParts);
QPoint position = event->pos();
QPoint hotSpot;
QList<QByteArray> hotSpotPos = mime->data("application/x-hotspot").split(' ');
if (hotSpotPos.size() == 2) {
hotSpot.setX(hotSpotPos.first().toInt());
hotSpot.setY(hotSpotPos.last().toInt());
}
foreach (QString piece, pieces) {
DragLabel *newLabel = new DragLabel(piece, this);
newLabel->move(position - hotSpot);
newLabel->show();
newLabel->setAttribute(Qt::WA_DeleteOnClose);
position += QPoint(newLabel->width(), 0);
}
if (event->source() == this) {
event->setDropAction(Qt::MoveAction);
event->accept();
} else {
event->acceptProposedAction();
}
} else {
示例2: dataStream
//! [9]
void DragWidget::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasFormat("application/x-fridgemagnet")) {
const QMimeData *mime = event->mimeData();
//! [9] //! [10]
QByteArray itemData = mime->data("application/x-fridgemagnet");
QDataStream dataStream(&itemData, QIODevice::ReadOnly);
QString text;
QPoint offset;
dataStream >> text >> offset;
//! [10]
//! [11]
DragLabel *newLabel = new DragLabel(text, this);
newLabel->move(event->pos() - offset);
newLabel->show();
newLabel->setAttribute(Qt::WA_DeleteOnClose);
if (event->source() == this) {
event->setDropAction(Qt::MoveAction);
event->accept();
} else {
event->acceptProposedAction();
}
//! [11] //! [12]
} else if (event->mimeData()->hasText()) {
示例3: QWidget
DragWidget::DragWidget(QWidget *parent)
: QWidget(parent)
{
QFile dictionaryFile(":/dictionary/words.txt");
dictionaryFile.open(QIODevice::ReadOnly);
QTextStream inputStream(&dictionaryFile);
int x = 5;
int y = 5;
while (!inputStream.atEnd()) {
QString word;
inputStream >> word;
if (!word.isEmpty()) {
DragLabel *wordLabel = new DragLabel(word, this);
wordLabel->move(x, y);
wordLabel->show();
x += wordLabel->width() + 2;
if (x >= 195) {
x = 5;
y += wordLabel->height() + 2;
}
}
}
QPalette newPalette = palette();
newPalette.setColor(QPalette::Window, Qt::white);
setPalette(newPalette);
setAcceptDrops(true);
setMinimumSize(400, qMax(200, y));
setWindowTitle(tr("Draggable Text"));
}
示例4: foreach
foreach (QString piece, pieces) {
DragLabel *newLabel = new DragLabel(piece, this);
newLabel->move(position);
newLabel->show();
position += QPoint(newLabel->width(), 0);
}
示例5: foreach
foreach (QString piece, pieces) {
DragLabel *newLabel = new DragLabel(piece, this);
newLabel->move(position);
newLabel->show();
newLabel->setAttribute(Qt::WA_DeleteOnClose);
position += QPoint(newLabel->width(), 0);
}
示例6: QWidget
DragWidget::DragWidget(QWidget *parent)
: QWidget(parent)
{
QFile dictionaryFile(":/words.txt");
if (dictionaryFile.exists() == false)
{
qDebug() << "words file doesn't exist";
// 因为此时QT的时间循环尚未开始,故exit, quit, closeAllWindows 都不起作用。
// qApp->exit(-1);
// qApp->quit();
// qApp->closeAllWindows();
QTimer::singleShot(0, qApp, SLOT(quit()));
}
dictionaryFile.open(QIODevice::ReadOnly);
QTextStream inputStream(&dictionaryFile);
int x = 5;
int y = 5;
while (inputStream.atEnd() == false)
{
QString word;
inputStream >> word;
if (word.isEmpty() == false)
{
DragLabel *wordLabel = new DragLabel(word, this);
wordLabel->move(x, y);
wordLabel->show();
x += wordLabel->width() + 2;
if (x >= 195)
{
x = 5;
y += wordLabel->height() + 2;
}
}
}
QPalette newPalette = palette();
newPalette.setColor(QPalette::Window, Qt::yellow);
setPalette(newPalette);
// 接受鼠标拖拽, that's important!
setAcceptDrops(true);
setMinimumSize(400, qMax(200, y));
setWindowTitle("Dragable Text");
}
示例7: stream
void DragWidget::dropEvent(QDropEvent * e)
{
if (e->mimeData()->hasFormat("Drag-Text"))
{
QByteArray data = e->mimeData()->data("Drag-Text");
QDataStream stream(&data,QIODevice::ReadOnly);
QString text;
QPoint offset;
stream >> text >> offset;
DragLabel *label = new DragLabel(text,this);
label->move(e->pos() - offset);
label->show();
if (children().contains(e->source()))
{
e->setDropAction(Qt::MoveAction);
e->accept();
}
else
e->acceptProposedAction();
}
示例8: QWidget
//! [0]
DragWidget::DragWidget(QWidget *parent)
: QWidget(parent)
{
QFile dictionaryFile(":/dictionary/words.txt");
dictionaryFile.open(QFile::ReadOnly);
QTextStream inputStream(&dictionaryFile);
//! [0]
//! [1]
int x = 5;
int y = 5;
while (!inputStream.atEnd()) {
QString word;
inputStream >> word;
if (!word.isEmpty()) {
DragLabel *wordLabel = new DragLabel(word, this);
wordLabel->move(x, y);
wordLabel->show();
wordLabel->setAttribute(Qt::WA_DeleteOnClose);
x += wordLabel->width() + 2;
if (x >= 245) {
x = 5;
y += wordLabel->height() + 2;
}
}
}
//! [1]
//! [2]
QPalette newPalette = palette();
newPalette.setColor(QPalette::Window, Qt::white);
setPalette(newPalette);
setMinimumSize(400, qMax(200, y));
setWindowTitle(tr("Fridge Magnets"));
//! [2] //! [3]
setAcceptDrops(true);
}
示例9: QWidget
FridgeMagnet::FridgeMagnet(QWidget *parent)
: QWidget(parent)
{
setWindowTitle(tr("Fridge Magnets"));
setAcceptDrops(true);
//
QString fileName;
fileName = qmPath + "/words.txt";
QFile dictionaryFile(fileName);
dictionaryFile.open(QFile::ReadOnly);
QTextStream inputStream(&dictionaryFile);
int x = 5;
int y = 5;
while (! inputStream.atEnd()) {
QString word;
inputStream >> word;
if (!word.isEmpty()) {
DragLabel *wordLabel = new DragLabel(word, this);
wordLabel->move(x, y);
wordLabel->show();
wordLabel->setAttribute(Qt::WA_DeleteOnClose);
x += wordLabel->width() + 2;
if (x >= 245) {
x = 5;
y += wordLabel->height() + 2;
}
}
}
}
示例10: QWidget
//! [0]
DragWidget::DragWidget(QWidget *parent)
: QWidget(parent)
{
QFile dictionaryFile(":/dictionary/words.txt");
dictionaryFile.open(QFile::ReadOnly);
QTextStream inputStream(&dictionaryFile);
//! [0]
//! [1]
int x = 5;
int y = 5;
while (!inputStream.atEnd()) {
QString word;
inputStream >> word;
if (!word.isEmpty()) {
DragLabel *wordLabel = new DragLabel(word, this);
wordLabel->move(x, y);
wordLabel->show();
wordLabel->setAttribute(Qt::WA_DeleteOnClose);
x += wordLabel->width() + 2;
#if defined(Q_WS_MAEMO_5) || defined(Q_WS_SIMULATOR)
if (x >= 345) {
#else
if (x >= 245) {
#endif
x = 5;
y += wordLabel->height() + 2;
}
}
}
//! [1]
//! [2]
#ifndef Q_WS_S60
//Fridge magnets is used for demoing Qt on S60 and themed backgrounds look better than white
QPalette newPalette = palette();
newPalette.setColor(QPalette::Window, Qt::white);
setPalette(newPalette);
#endif
setMinimumSize(400, qMax(200, y));
setWindowTitle(tr("Fridge Magnets"));
//! [2] //! [3]
setAcceptDrops(true);
}
//! [3]
//! [4]
void DragWidget::dragEnterEvent(QDragEnterEvent *event)
{
//! [4] //! [5]
if (event->mimeData()->hasFormat("application/x-fridgemagnet")) {
if (children().contains(event->source())) {
event->setDropAction(Qt::MoveAction);
event->accept();
} else {
event->acceptProposedAction();
//! [5] //! [6]
}
//! [6] //! [7]
} else if (event->mimeData()->hasText()) {
event->acceptProposedAction();
} else {
event->ignore();
}
}
//! [7]
//! [8]
void DragWidget::dragMoveEvent(QDragMoveEvent *event)
{
if (event->mimeData()->hasFormat("application/x-fridgemagnet")) {
if (children().contains(event->source())) {
event->setDropAction(Qt::MoveAction);
event->accept();
} else {
event->acceptProposedAction();
}
} else if (event->mimeData()->hasText()) {
event->acceptProposedAction();
} else {
event->ignore();
}
}
//! [8]
//! [9]
void DragWidget::dropEvent(QDropEvent *event)
{
if (event->mimeData()->hasFormat("application/x-fridgemagnet")) {
const QMimeData *mime = event->mimeData();
//! [9] //! [10]
QByteArray itemData = mime->data("application/x-fridgemagnet");
QDataStream dataStream(&itemData, QIODevice::ReadOnly);
QString text;
QPoint offset;
dataStream >> text >> offset;
//.........这里部分代码省略.........