本文整理汇总了C++中QDrag::start方法的典型用法代码示例。如果您正苦于以下问题:C++ QDrag::start方法的具体用法?C++ QDrag::start怎么用?C++ QDrag::start使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDrag
的用法示例。
在下文中一共展示了QDrag::start方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: mouseMoveEvent
void task_list::mouseMoveEvent(QMouseEvent *event)
{
// if not left button - return
if (!(event->buttons() & Qt::LeftButton)) return;
// if no item selected, return (else it would crash)
if (currentItem() == NULL) return;
if(currentItem()->type()==0)
{
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
// construct list of QUrls
// other widgets accept this mime type, we can drop to them
QList<QUrl> list;
list.append(QUrl(this->currentItem()->text(0)));
list.append(QUrl(this->currentItem()->text(1)));
list.append(QUrl(this->currentItem()->text(2)));
list.append(QUrl(this->currentItem()->text(3)));
list.append(QUrl(this->currentItem()->text(4)));
// mime stuff
mimeData->setUrls(list);
drag->setMimeData(mimeData);
// start drag
drag->start(Qt::CopyAction | Qt::MoveAction);
}
if(currentItem()->type()==1)
{
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
// construct list of QUrls
// other widgets accept this mime type, we can drop to them
QList<QUrl> list;
list.append(QUrl(this->currentItem()->text(0)));
list.append(QUrl(this->currentItem()->text(1)));
list.append(QUrl(this->currentItem()->text(2)));
list.append(QUrl(this->currentItem()->text(3)));
list.append(QUrl(this->currentItem()->text(4)));
// mime stuff
mimeData->setUrls(list);
drag->setMimeData(mimeData);
// start drag
drag->start( Qt::CopyAction | Qt::MoveAction);
}
}
示例2: mousePressEvent
void CTreeView::mousePressEvent(QMouseEvent *event)
{
// if not left button - return
QTreeView::mousePressEvent(event);
if (!(event->buttons() & Qt::LeftButton))
{
return;
}
// if no item selected, return (else it would crash)
QModelIndex index = currentIndex();
if (index.isValid() == false)
{
return;
}
if (index.parent().isValid() == false)
{
return;
}
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
// construct list of QUrls
// other widgets accept this mime type, we can drop to them
QList<QUrl> list;
list.push_back(index.parent().child(index.row(), 0).data().toUrl());
list.push_back(index.parent().child(index.row(), 1).data().toUrl());
// mime stuff
mimeData->setUrls(list);
mimeData->setText("Item");
drag->setMimeData(mimeData);
// start drag
drag->start(Qt::CopyAction | Qt::MoveAction);
}
示例3: mouseMoveEvent
void FinalWidget::mouseMoveEvent(QMouseEvent *event)
{
if (!(event->buttons() & Qt::LeftButton))
return;
if ((event->pos() - dragStartPosition).manhattanLength()
< QApplication::startDragDistance())
return;
if (!hasImage)
return;
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
//! [0]
QByteArray output;
QBuffer outputBuffer(&output);
outputBuffer.open(QIODevice::WriteOnly);
imageLabel->pixmap()->toImage().save(&outputBuffer, "PNG");
mimeData->setData("image/png", output);
//! [0]
/*
//! [1]
mimeData->setImageData(QVariant(*imageLabel->pixmap()));
//! [1]
*/
drag->setMimeData(mimeData);
drag->setPixmap(imageLabel->pixmap()->scaled(64, 64, Qt::KeepAspectRatio));
//! [2]
drag->setHotSpot(QPoint(drag->pixmap().width()/2,
drag->pixmap().height()));
//! [2]
drag->start();
}
示例4: mousePressEvent
void bottom_label::mousePressEvent(QMouseEvent *event){
if (event->button() == Qt::LeftButton) {
QDrag* drag = new QDrag(this);
//const QPixmap *pPixmap = pixmap();
// drag->setPixmap(*pPixmap); //ÕâÀïÉèÖÃÍÏקʱ¸úËæÊó±êµÄͼƬ
//int w=pPixmap->size().width();
//int h=pPixmap->size().height();
//QPoint t;
//t.setX(w);
//t.setY(h);
// drag->setHotSpot(t); //ÉèÖøúËæͼƬµÄÖÐÐĵã
QMimeData *mimeData = new QMimeData;
QString send_mes = QString::number(id);
send_mes += "|2";
mimeData->setText(send_mes);
drag->setMimeData(mimeData);
//drag->setPixmap(iconPixmap);
Qt::DropAction dropAction = drag->exec();
drag->start(Qt::MoveAction);
}
}
示例5: mouseMoveEvent
/*
* Used for starting drags of tabs
*/
void PsiTabBar::mouseMoveEvent(QMouseEvent *event) {
if (!dragsEnabled_) {
return;
}
if (!(event->buttons() & Qt::LeftButton)) {
return;
}
if ((event->pos() - dragStartPosition_).manhattanLength()
< QApplication::startDragDistance()) {
return;
}
if (dragTab_ != -1) {
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
QByteArray data;
QPixmap icon;
data.setNum(dragTab_);
mimeData->setData("psiTabDrag", data);
drag->setMimeData(mimeData);
drag->setPixmap(icon);
Qt::DropAction dropAction = drag->start(Qt::MoveAction);
Q_UNUSED(dropAction);
}
event->accept();
}
示例6: mouseMoveEvent
void DualColorButton::mouseMoveEvent(QMouseEvent *event)
{
if(dragSource_ != NODRAG && (event->buttons() & Qt::LeftButton) &&
(event->pos() - dragStart_).manhattanLength()
> QApplication::startDragDistance())
{
QDrag *drag = new QDrag(this);
QMimeData *mimedata = new QMimeData;
const QColor color = (dragSource_ == FOREGROUND)?foreground_:background_;
mimedata->setColorData(color);
drag->setMimeData(mimedata);
drag->start(Qt::CopyAction);
}
// Higlight clickable areas
QRectF fgr = foregroundRect();
QRectF bgr = backgroundRect();
if(fgr.contains(event->pos()))
hilite_ = 1;
else if(bgr.contains(event->pos()))
hilite_ = 2;
else if(event->pos().x() > fgr.right() && event->pos().y() < bgr.top())
hilite_ = 3;
else if(event->pos().x() < bgr.left() && event->pos().y() > fgr.bottom())
hilite_ = 4;
else
hilite_ = 0;
update();
}
示例7: mouseMoveEvent
void PlayListView::mouseMoveEvent(QMouseEvent *event){
//
// if not left button - return
if (!(event->buttons() & Qt::LeftButton)) return;
// if no item selected, return (else it would crash)
if (currentItem() == NULL) return;
QDrag *drag = new QDrag(this);
QMimeData *mimeData = new QMimeData;
// construct list of QUrls
// other widgets accept this mime type, we can drop to them
QList<QUrl> list;
QString line;
line = currentItem()->text(0); // 0 == first Column of QTreeWidgetItem
list.append( QUrl(line) ); // only QUrl in list will be text of actual item
// mime stuff
mimeData->setUrls(list);
//mimeData->setData( line.toUtf8(), "text/uri-list" );
drag->setMimeData(mimeData);
RG_DEBUG << "Starting drag from PlayListView::mouseMoveEvent() with mime : " << mimeData->formats() << " - " << mimeData->urls()[0] << endl;
// start drag
drag->start(Qt::CopyAction | Qt::MoveAction);
}
示例8: mousePressEvent
void DragLabel::mousePressEvent(QMouseEvent * e)
{
QString str = text();
QPixmap pix;
pix = pix.grabWidget(this);
QByteArray data;
QDataStream stream(&data,QIODevice::WriteOnly);
stream << str << QPoint(e->pos()-rect().topLeft());
QMimeData *mimeData = new QMimeData;
mimeData->setData("Drag-Text",data);
mimeData->setText(str);
QDrag *drag = new QDrag(this);
drag->setMimeData(mimeData);
drag->setHotSpot(QPoint(e->pos() - rect().topLeft()));
drag->setPixmap(pix);
hide();
Qt::DropAction dropAction = drag->start(Qt::CopyAction | Qt::MoveAction);
if (dropAction == Qt::MoveAction)
close();
else
show();
}
示例9: mouseMoveEvent
void PanelBrowserMenu::mouseMoveEvent(QMouseEvent *e)
{
QMenu::mouseMoveEvent(e);
if (!(e->buttons() & Qt::LeftButton)) return;
if(_lastpress == QPoint(-1, -1)) return;
// DND delay
if((_lastpress - e->pos()).manhattanLength() < 12) return;
// get id
int id = static_cast<QMenuItem*>(actionAt(_lastpress))->id();
if(!_filemap.contains(id)) return;
// reset _lastpress
_lastpress = QPoint(-1, -1);
// start drag
KUrl url;
url.setPath(path() + '/' + _filemap[id]);
KUrl::List files(url);
QDrag* drag = new QDrag(this);
QMimeData* data = new QMimeData;
files.populateMimeData(data);
connect(drag, SIGNAL(destroyed(QObject*)), this, SLOT(dragObjectDestroyed(QObject*)));
drag->setPixmap(iconSet(id).pixmap());
drag->start();
}
示例10: startDrag
void QDesignerMenuBar::startDrag(const QPoint &pos)
{
const int index = findAction(pos);
if (m_currentIndex == -1 || index >= realActionCount())
return;
QAction *action = safeActionAt(index);
QDesignerFormWindowInterface *fw = formWindow();
RemoveActionFromCommand *cmd = new RemoveActionFromCommand(fw);
cmd->init(this, action, actions().at(index + 1));
fw->commandHistory()->push(cmd);
adjustSize();
hideMenu(index);
QDrag *drag = new QDrag(this);
drag->setPixmap(ActionRepositoryMimeData::actionDragPixmap(action));
drag->setMimeData(new ActionRepositoryMimeData(action, Qt::MoveAction));
const int old_index = m_currentIndex;
m_currentIndex = -1;
if (drag->start(Qt::MoveAction) == Qt::IgnoreAction) {
InsertActionIntoCommand *cmd = new InsertActionIntoCommand(fw);
cmd->init(this, action, safeActionAt(index));
fw->commandHistory()->push(cmd);
m_currentIndex = old_index;
adjustSize();
}
}
示例11: mouseMoveEvent
void KonqCombo::mouseMoveEvent( QMouseEvent *e )
{
KComboBox::mouseMoveEvent( e );
if ( m_dragStart.isNull() || currentText().isEmpty() )
return;
if ( e->buttons() & Qt::LeftButton &&
(e->pos() - m_dragStart).manhattanLength() >
KGlobalSettings::dndEventDelay() )
{
KUrl url( currentText() );
if ( url.isValid() )
{
QDrag* drag = new QDrag(this);
QMimeData* mime = new QMimeData();
url.populateMimeData(mime);
drag->setMimeData(mime);
QPixmap pix = KonqPixmapProvider::self()->pixmapFor( currentText(),
KIconLoader::SizeMedium );
if ( !pix.isNull() )
drag->setPixmap( pix );
drag->start();
}
}
}
示例12: mouseMoveEvent
void UserView::mouseMoveEvent(QMouseEvent* event)
{
UserViewBase::mouseMoveEvent(event);
QModelIndex index = currentIndex();
if (index.isValid() == false)
return;
if (static_cast<ContactListModel::ItemType>
(index.data(ContactListModel::ItemTypeRole).toInt()) != ContactListModel::UserItem)
return;
QString id = index.data(ContactListModel::AccountIdRole).toString();
unsigned long ppid = index.data(ContactListModel::PpidRole).toUInt();
if ((event->buttons() & Qt::LeftButton) && !myMousePressPos.isNull() &&
(QPoint(event->pos() - myMousePressPos).manhattanLength() >= QApplication::startDragDistance()))
{
QString data(Licq::protocolId_toString(ppid).c_str());
data += id;
QDrag* drag = new QDrag(this);
QMimeData* mimeData = new QMimeData;
mimeData->setText(data);
drag->setMimeData(mimeData);
drag->start(Qt::CopyAction);
}
}
示例13: initiateDrag
void Test::initiateDrag( QWidget *w )
{
QDrag *drag = new QDrag( this );
QMimeData *mimeData = new QMimeData;
mimeData->setText(mWidget->tabText( mWidget->indexOf(w)));
drag->setMimeData(mimeData);
drag->start(); // do NOT delete d.
}
示例14: startDrag
void ImageButton::startDrag()
{
if ( !mPicture.data().isNull() ) {
QDrag *drag = new QDrag( this );
drag->setMimeData( new QMimeData() );
drag->mimeData()->setImageData( mPicture.data() );
drag->start();
}
}
示例15: mouseMoveEvent
void Palette::mouseMoveEvent(QMouseEvent* ev)
{
if ((currentIdx != -1) && (dragIdx == currentIdx) && (ev->buttons() & Qt::LeftButton)
&& (ev->pos() - dragStartPosition).manhattanLength() > QApplication::startDragDistance()) {
PaletteCell* cell = cells[currentIdx];
if (cell && cell->element) {
QDrag* drag = new QDrag(this);
QMimeData* mimeData = new QMimeData;
Element* el = cell->element;
qreal mag = PALETTE_SPATIUM * extraMag / gscore->spatium();
QPointF spos = QPointF(dragStartPosition) / mag;
spos -= QPointF(cells[currentIdx]->x, cells[currentIdx]->y);
// DEBUG:
spos.setX(0.0);
mimeData->setData(mimeSymbolFormat, el->mimeData(spos));
drag->setMimeData(mimeData);
dragSrcIdx = currentIdx;
emit startDragElement(el);
if (_readOnly) {
drag->start(Qt::CopyAction);
}
else {
/*Qt::DropAction action = */
drag->start(Qt::DropActions(Qt::CopyAction | Qt::MoveAction));
}
}
}
else {
QRect r;
if (currentIdx != -1)
r = idxRect(currentIdx);
currentIdx = idx(ev->pos());
if (currentIdx != -1) {
if (cells[currentIdx] == 0)
currentIdx = -1;
else
r |= idxRect(currentIdx);
}
update(r);
}
}