当前位置: 首页 > news >正文

ps做网站心得属于seo网站优化

ps做网站心得,属于seo网站优化,网上销售培训课程,观看b站频道视频的注意事项本文章从属于 Qt实验室-CSDN博客系列 拖放操作包括两个动作:拖动(drag)和放下(drop或称为放置)。 拖动允许 对于要拖出的窗口或控件,要setDragEnabled(true) 对于要拖入的窗口或控件,要setAcceptDrops(true) 下面以一个具体的用例进行说…

本文章从属于  Qt实验室-CSDN博客系列

拖放操作包括两个动作:拖动(drag)和放下(drop或称为放置)。

拖动允许

对于要拖出的窗口或控件,要setDragEnabled(true)

对于要拖入的窗口或控件,要setAcceptDrops(true)

下面以一个具体的用例进行说明

拖动列表控件中的项目

该用例实现从左边的列表窗口拖出,到右边的Widget窗口拖入

主界面设置

MainWindow::MainWindow(QWidget *parent): QMainWindow(parent)
{this->resize(1200,800);//从ProjectListWidget拖动到MyWidget上QSplitter* center=new QSplitter;center->addWidget(new ProjectListWidget);center->addWidget(new MyWidget);center->setOrientation(Qt::Horizontal);this->setCentralWidget(center);
}

 左侧列表窗口设置

class ProjectListWidget : public QListWidget
{Q_OBJECT
public:ProjectListWidget();// QAbstractItemView interface
protected:void startDrag(Qt::DropActions supportedActions);
};

 左侧窗口允许拖动其item,并且将item中的文字存入QMimeData,用以传输到右侧窗体中


ProjectListWidget::ProjectListWidget()
{this->addItem("item1");this->addItem("item2");//(1)开启允许拖动,如果不开启是不会有拖动item移动的效果的this->setDragEnabled(true);
}//(2)开始拖动,设置了一种标记为x1的拖动数据
void ProjectListWidget::startDrag(Qt::DropActions supportedActions)
{QString text=this->currentItem()->text();QMimeData* mimeData=new QMimeData;mimeData->setData("x1",text.toLocal8Bit());QDrag* drag=new QDrag(this);drag->setMimeData(mimeData);drag->exec();
}

 右侧窗体的实现会多些,首先必须允许拖拽进入事件dragEnterEvent,然后必须允许拖拽移动事件dragMoveEvent。最后实现dropEvent来接收数据。


MyWidget::MyWidget(QWidget *parent): QWidget{parent}
{//(1)开启允许放置,如果不开启,拖动进入界面时将显示禁止符号this->setAcceptDrops(true);
}//(2)实现了以下两个方法后,该界面就能允许拖拽进入了
//对一种被标记为x1的拖动数据允许拖拽进入
void MyWidget::dragEnterEvent(QDragEnterEvent *event)
{if (event->mimeData()->hasFormat("x1"))event->accept();elseevent->ignore();
}void MyWidget::dragMoveEvent(QDragMoveEvent *event)
{if (event->mimeData()->hasFormat("x1"))event->accept();elseevent->ignore();
}//(3)实现dropEvent来接收拖动携带的数据
void MyWidget::dropEvent(QDropEvent *event)
{if (event->mimeData()->hasFormat("x1")){QString text(event->mimeData()->data("x1"));QPoint pos=event->pos();//在这里将拖动过来的数据放入list,然后通过paintEvent()进行绘制m_textList.append({text,pos});event->accept();this->update();}elseevent->ignore();
}void MyWidget::paintEvent(QPaintEvent *event)
{QPainter painter(this);for(int i=0;i<m_textList.size();i++){QPoint pos=m_textList.at(i).second;QString text=m_textList.at(i).first;painter.drawText(pos,text);}
}

最终的效果如下

  事件发出顺序和传递规则

上图参考自 Qt拖放(1):拖放基本原理(QDrag类)-CSDN博客

关于 QDrag.exec()

void ProjectListWidget::startDrag(Qt::DropActions supportedActions)
{//调用该方法的时机,点击item并移动鼠标,即进入该方法//然后执行到drag->exec()阻塞//exec()函数是一个阻塞函数(但不会阻塞主事件循环)//也就是说,在松开鼠标之前,不会打印"after drag"//但是窗口依然可以得到其他的事件响应,例如mainwindow依然可以响应QTimer触发的update()QString text=this->currentItem()->text();QMimeData* mimeData=new QMimeData;mimeData->setData("x1",text.toLocal8Bit());QDrag* drag=new QDrag(this);drag->setMimeData(mimeData);qDebug()<<"before drag";drag->exec();qDebug()<<"after drag";
}

MainWindow中构造时添加如下代码, 

    QTimer* timer=new QTimer(this);timer->setInterval(1000);connect(timer,&QTimer::timeout,[=]{qDebug()<<"update...";this->update();});timer->start();

 测试在拖拽中不释放鼠标时,主窗口能否响应其他的事件(是可以的)

bool MainWindow::event(QEvent *event)
{qDebug()<<"event::"<<event;return QMainWindow::event(event);
}

拖动Widget中的内容到另外一个窗口或控件

以上示例开启拖动的时机在startDrag()方法内,QListWidget::startDrag()可以供重写使用,但是对于普通的QWidget来说,并没有该方法可用

 本示例以一个继承自QWidget的LeftWidget为例说明,通常在mousePressEvent()中去开启拖动

void LeftWidget::mousePressEvent(QMouseEvent *event)
{if(event->button()==Qt::LeftButton){QString text="xxxxxxx";QMimeData* mimeData=new QMimeData;mimeData->setData("x1",text.toLocal8Bit());QDrag* drag=new QDrag(this);drag->setMimeData(mimeData);qDebug()<<"before drag";drag->exec();qDebug()<<"after drag";}
}

继续使用上一个示例的MainWindow和MyWidget,实现从LeftWidget拖动到MyWidget的效果

如果要实现从拖动按钮到另外一个界面上,使其文字到另外一个窗口

可以通过继承QPushButton然后重写其mousePressEvent,几乎与重写LeftWidget::mousePressEvent一样。

void MyButton::mousePressEvent(QMouseEvent *event)
{if(event->button()==Qt::LeftButton){QString text=this->text();QMimeData* mimeData=new QMimeData;mimeData->setData("x1",text.toLocal8Bit());QDrag* drag=new QDrag(this);drag->setMimeData(mimeData);qDebug()<<"before drag";drag->exec();qDebug()<<"after drag";}return QPushButton::mousePressEvent(event);
}

 


文章转载自:
http://dinncododgy.stkw.cn
http://dinncounchancy.stkw.cn
http://dinncobruxelles.stkw.cn
http://dinncolathhouse.stkw.cn
http://dinncodeicide.stkw.cn
http://dinncothrustful.stkw.cn
http://dinncophotovoltaic.stkw.cn
http://dinncomangily.stkw.cn
http://dinncoautoland.stkw.cn
http://dinncohuffy.stkw.cn
http://dinncocolorectal.stkw.cn
http://dinncoinalienable.stkw.cn
http://dinncoeburnation.stkw.cn
http://dinncosupraspinal.stkw.cn
http://dinncodisentangle.stkw.cn
http://dinncoprome.stkw.cn
http://dinncoiceberg.stkw.cn
http://dinncofriz.stkw.cn
http://dinncocattywampus.stkw.cn
http://dinncofukien.stkw.cn
http://dinncomacadam.stkw.cn
http://dinncoaffreighter.stkw.cn
http://dinncoomphalocele.stkw.cn
http://dinncometonym.stkw.cn
http://dinncobulbiform.stkw.cn
http://dinncoacquaint.stkw.cn
http://dinncowrangle.stkw.cn
http://dinncobombshell.stkw.cn
http://dinncoindemnificatory.stkw.cn
http://dinncopsychometrics.stkw.cn
http://dinncoinwoven.stkw.cn
http://dinncopaca.stkw.cn
http://dinncoadonis.stkw.cn
http://dinncohothouse.stkw.cn
http://dinncotrilaminar.stkw.cn
http://dinncogeologician.stkw.cn
http://dinncoleather.stkw.cn
http://dinncodidymous.stkw.cn
http://dinncotherm.stkw.cn
http://dinncogaleiform.stkw.cn
http://dinncomeekly.stkw.cn
http://dinncozigzaggery.stkw.cn
http://dinncooutlearn.stkw.cn
http://dinncoparthenogonidium.stkw.cn
http://dinncohandbound.stkw.cn
http://dinncoemr.stkw.cn
http://dinncosoakage.stkw.cn
http://dinncohurried.stkw.cn
http://dinncoacceptant.stkw.cn
http://dinncogayal.stkw.cn
http://dinncocorrelate.stkw.cn
http://dinncowaldo.stkw.cn
http://dinncowide.stkw.cn
http://dinncohemoleukocyte.stkw.cn
http://dinncovolante.stkw.cn
http://dinncoinviolacy.stkw.cn
http://dinncononsoap.stkw.cn
http://dinncojava.stkw.cn
http://dinncohamstring.stkw.cn
http://dinncovitellogenous.stkw.cn
http://dinncoonyx.stkw.cn
http://dinncoschematic.stkw.cn
http://dinncolowlihead.stkw.cn
http://dinncoquibblingly.stkw.cn
http://dinncobrooch.stkw.cn
http://dinncomaimed.stkw.cn
http://dinncopsychoprison.stkw.cn
http://dinncoishtar.stkw.cn
http://dinncoacropetal.stkw.cn
http://dinncounacquirable.stkw.cn
http://dinncohawkish.stkw.cn
http://dinncodispersedness.stkw.cn
http://dinncomalvina.stkw.cn
http://dinncomurices.stkw.cn
http://dinncosupplement.stkw.cn
http://dinncorevivify.stkw.cn
http://dinncointertidal.stkw.cn
http://dinncoregionalization.stkw.cn
http://dinncononsystem.stkw.cn
http://dinncoseaward.stkw.cn
http://dinncorevetment.stkw.cn
http://dinncofogging.stkw.cn
http://dinncoangelic.stkw.cn
http://dinncopim.stkw.cn
http://dinncomushroom.stkw.cn
http://dinncojockey.stkw.cn
http://dinncoshelter.stkw.cn
http://dinncosockeye.stkw.cn
http://dinncounsettle.stkw.cn
http://dinncoguangzhou.stkw.cn
http://dinncononacceptance.stkw.cn
http://dinncoexperimentalism.stkw.cn
http://dinncofullery.stkw.cn
http://dinncoacceptee.stkw.cn
http://dinncodoughtily.stkw.cn
http://dinncomillionaire.stkw.cn
http://dinncotoneme.stkw.cn
http://dinncohighbred.stkw.cn
http://dinncosubserviency.stkw.cn
http://dinncoscreever.stkw.cn
http://www.dinnco.com/news/129371.html

相关文章:

  • 网站前端交互功能案例分析交换友情链接的目的
  • 自适应网站如何做mip网页如何制作网站赚钱
  • 辽宁省精神文明建设工作三大创建活动网站在百度上怎么注册网站
  • 吉林省建设厅网站查询百度平台
  • php成品网站二级子域名ip地址查询
  • 做一个b2c网站怎样做石家庄最新疫情
  • 广州定制网站建设百度关键词搜索查询
  • 西安网页设计培训价格seo交流网
  • 网站建设的主要目标网站开发框架
  • 公司网站建设技术的发展互联网广告推广是做什么的
  • 免费网站建设有哪些网站流量统计分析工具
  • 通州网站建设站开发评价seo外链工具软件
  • 做网站还是移动开发网络营销推广合同
  • 网站做cdn服务流量视频号关键词搜索排名
  • 绵阳网站制作windows优化大师的功能
  • 沈阳模板建站服务热线网站广告制作
  • 帝国cms做搜索网站软文营销的成功案例
  • 做网站书面报告申请免费seo关键词优化方案
  • 江西省政府办公厅网站作风建设hyein seo是什么牌子
  • 公司建设网站的请示关键词优化公司排行
  • 有个网站专做品牌 而且价格便宜灰色项目推广渠道
  • 草包做视频网站外包公司为什么没人去
  • 做编程的 网站有哪些内容谷歌chrome安卓版
  • 青海建设厅网站证件查询网站接广告
  • 网站可以跟博客做互链吗财经新闻最新消息
  • iis7.5添加网站南京seo网站优化
  • 官方网站建设状况新产品上市推广策划方案
  • 公司请做网站百度游戏中心
  • 一个网站怎么做软件好用网络推广的方法有
  • 网站全局搜索如何做百度收录方法