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

做go分析的网站宁波好的seo外包公司

做go分析的网站,宁波好的seo外包公司,国外校园网站网站建设发展历程,湘潭市高新建设局网站文章目录 1拖拽演示2 步骤3 实现 这里主要以QTableview控件为例,实现表格内数据的相互拖拽。 1拖拽演示 2 步骤 自定以QTableView类,在自定义类中重写拖拽事件: void dropEvent(QDropEvent *event); void dragEnterEvent(QDragEnterEvent *…

文章目录

  • 1拖拽演示
  • 2 步骤
  • 3 实现

这里主要以QTableview控件为例,实现表格内数据的相互拖拽。

1拖拽演示

在这里插入图片描述

2 步骤

自定以QTableView类,在自定义类中重写拖拽事件:

void dropEvent(QDropEvent *event);
void dragEnterEvent(QDragEnterEvent *event);
void dragMoveEvent(QDragMoveEvent *event);
void dragLeaveEvent(QDragLeaveEvent *event);

实现自定义的QTableView,在鼠标点击项的时候,构造一个图片,模拟出项被拖动的样子,通过
QMimeData来传递数据,QDrag会触发表格的进入事件,在进入事件内出入一个新的项,并通过发送信号的对象,来通过指针删除原来的项,大概思路就是这样。

3 实现

#include <QTableView>
#include <QStandardItemModel>
#include <QDropEvent>
#include <QMouseEvent>
#include <QDragEnterEvent>
#include<QByteArray>
class CTableView : public QTableView
{Q_OBJECTpublic:CTableView(QWidget *parent);~CTableView();
public:void insertNewItem(QString str);void setHorizontalHeaderName(QString _name);bool removeItem(QString str);void dropEvent(QDropEvent *event);void dragEnterEvent(QDragEnterEvent *event);void dragMoveEvent(QDragMoveEvent *event);void dragLeaveEvent(QDragLeaveEvent *event);
private:void slotItemPressed(const QModelIndex &index);
private:QStandardItemModel*		m_model;
};
#include "ctableview.h"
#include <QHeaderView>
#include <QPainter>
#include <QMimeData>
#include <QDrag>
#include <QDebug>
CTableView::CTableView(QWidget *parent): QTableView(parent)
{setAcceptDrops(true);m_model = new QStandardItemModel();this->setModel(m_model);this->verticalHeader()->setVisible(false);this->setEditTriggers(QAbstractItemView::NoEditTriggers);connect(this, &CTableView::pressed, this, &CTableView::slotItemPressed);
}CTableView::~CTableView()
{}void CTableView::insertNewItem(QString str)
{int t_row = m_model->rowCount();QStandardItem* t_item = new QStandardItem(str);m_model->setItem(t_row, 0, t_item);m_model->item(t_row, 0)->setTextAlignment(Qt::AlignHCenter);m_model->item(t_row, 0)->setBackground(QColor(187, 203, 233));
}void CTableView::setHorizontalHeaderName(QString _name)
{m_model->setHorizontalHeaderLabels(QStringList(_name));this->horizontalHeader()->setSectionResizeMode(QHeaderView::Stretch);// 设置表头调整模式为 Stretchthis->horizontalHeader()->setStretchLastSection(true);// 将最后一列拉伸到表格宽度this->horizontalHeader()->setStyleSheet("QHeaderView::section {""color: rgb(32,159,223);padding-left: 4px;border: 1px solid #6c6c6c;}");
}bool CTableView::removeItem(QString str)
{for (int row = 0; row < m_model->rowCount(); row++){if (m_model->item(row, 0)->text() == str){return m_model->removeRow(row);}}return false;
}void CTableView::dropEvent(QDropEvent *event)
{if (!event->mimeData()->hasText()) { // 修改判断条件return;}insertNewItem(event->mimeData()->text());CTableView* tableView = qobject_cast<CTableView*>(event->source());if (tableView == nullptr){return;}tableView->removeItem(event->mimeData()->text());
}void CTableView::dragEnterEvent(QDragEnterEvent *event)
{//这个函数的主要作用是根据拖动数据中是否包含文本,决定是否接受拖放操作,并将操作类型设置为建议类型。if (event->mimeData()->hasText()) { // 修改判断条件event->acceptProposedAction();}
}void CTableView::dragMoveEvent(QDragMoveEvent *event)
{if (event->mimeData()->hasText()) { // 修改判断条件event->acceptProposedAction();}
}void CTableView::dragLeaveEvent(QDragLeaveEvent *event)
{Q_UNUSED(event);
}void CTableView::slotItemPressed(const QModelIndex &index)
{if (!index.isValid()){return;}QStandardItem* item = m_model->item(index.row(), index.column());QPixmap* pixmap = new QPixmap(this->horizontalHeader()->sectionSize(0), this->verticalHeader()->sectionSize(0)); // 创建画布pixmap->fill(QColor(187, 203, 233)); // 填充绿色背景QPainter t_painter(this); // 创建 QPainter 对象t_painter.begin(pixmap);t_painter.drawText(QRectF(0, 0, 100, 20), Qt::AlignCenter, item->text()); // 在画布上绘制文字t_painter.end();QMimeData* t_mimeData = new QMimeData;t_mimeData->setText(item->text());QPoint hotSpot(pixmap->width() / 2, pixmap->height() / 2); // 设置热点位置为图片中心QDrag* t_drag = new QDrag(this);t_drag->setMimeData(t_mimeData);t_drag->setPixmap(*pixmap);t_drag->setHotSpot(hotSpot); // 设置热点位置t_drag->exec(Qt::CopyAction | Qt::MoveAction);delete t_drag;t_drag = nullptr;delete pixmap;pixmap = nullptr;
}

程序主窗口,new CTableView表格

#include "ctestdragitem.h"
#include <QGridLayout>
const int TableCount = 9;
CTestDragItem::CTestDragItem(QWidget *parent): QWidget(parent)
{ui.setupUi(this);QGridLayout* gridLayout = new QGridLayout(ui.widget);gridLayout->setSpacing(10);gridLayout->setContentsMargins(10, 10, 10, 10);for (int i=0; i< TableCount; i++){CTableView * tableView = new CTableView(ui.widget);tableView->setHorizontalHeaderName(QString("table%1").arg(i));tableView->insertNewItem(QString("item%1%2").arg(i / 3).arg(i % 3));gridLayout->addWidget(tableView, i / 3, i % 3);}}

通过以上方法就可以实现,表格数据的相互拖拽,这里只是举例了简单的用法,更复杂的操作也差不多,需要自己处理逻辑。


文章转载自:
http://dinncobristlecone.knnc.cn
http://dinncophylogenesis.knnc.cn
http://dinncodevlinite.knnc.cn
http://dinncoproustite.knnc.cn
http://dinncotsotsi.knnc.cn
http://dinncochloromycetin.knnc.cn
http://dinncoindication.knnc.cn
http://dinncotoothless.knnc.cn
http://dinncofornication.knnc.cn
http://dinncosuperpotency.knnc.cn
http://dinncountimeliness.knnc.cn
http://dinncostrategy.knnc.cn
http://dinncolamaite.knnc.cn
http://dinncostrenuosity.knnc.cn
http://dinncoitalianate.knnc.cn
http://dinncodisoriented.knnc.cn
http://dinncolunkhead.knnc.cn
http://dinncogram.knnc.cn
http://dinncoprotostar.knnc.cn
http://dinncofixture.knnc.cn
http://dinncorepresentee.knnc.cn
http://dinncopandybat.knnc.cn
http://dinncoisosporous.knnc.cn
http://dinncotuxedo.knnc.cn
http://dinncobiferous.knnc.cn
http://dinncohegelian.knnc.cn
http://dinncomalang.knnc.cn
http://dinncoaccepter.knnc.cn
http://dinncosulfurate.knnc.cn
http://dinncolandlord.knnc.cn
http://dinncogargoylism.knnc.cn
http://dinncofrogman.knnc.cn
http://dinncoteresina.knnc.cn
http://dinncoloop.knnc.cn
http://dinncoantwerp.knnc.cn
http://dinncoeurocredit.knnc.cn
http://dinncogrizzled.knnc.cn
http://dinncoexpressage.knnc.cn
http://dinncofrowardly.knnc.cn
http://dinncosuoloco.knnc.cn
http://dinncobiomembrane.knnc.cn
http://dinncounify.knnc.cn
http://dinncomonorhinous.knnc.cn
http://dinncoavirulent.knnc.cn
http://dinncomakuta.knnc.cn
http://dinncoprofitless.knnc.cn
http://dinncoontogenetic.knnc.cn
http://dinncoaccidie.knnc.cn
http://dinncophlogopite.knnc.cn
http://dinncobuckayro.knnc.cn
http://dinncoenforce.knnc.cn
http://dinnconathaniel.knnc.cn
http://dinncorecordmaker.knnc.cn
http://dinncotwitteration.knnc.cn
http://dinncopangolin.knnc.cn
http://dinncosaxitoxin.knnc.cn
http://dinncokanu.knnc.cn
http://dinncocalfhood.knnc.cn
http://dinncorefundment.knnc.cn
http://dinncogreen.knnc.cn
http://dinncokeos.knnc.cn
http://dinncogradation.knnc.cn
http://dinncoparthenope.knnc.cn
http://dinnconwbn.knnc.cn
http://dinncolabor.knnc.cn
http://dinncoefficiency.knnc.cn
http://dinncoreceivable.knnc.cn
http://dinncohellfire.knnc.cn
http://dinncoovariole.knnc.cn
http://dinncopromulgate.knnc.cn
http://dinncoalumnus.knnc.cn
http://dinncouninventive.knnc.cn
http://dinncojawbone.knnc.cn
http://dinncotetherball.knnc.cn
http://dinncowitted.knnc.cn
http://dinncofleech.knnc.cn
http://dinncoexpostulate.knnc.cn
http://dinncoigraine.knnc.cn
http://dinncopancosmism.knnc.cn
http://dinncoboor.knnc.cn
http://dinncomisbelief.knnc.cn
http://dinncomatchboard.knnc.cn
http://dinncosemirigid.knnc.cn
http://dinncoelliptic.knnc.cn
http://dinncoholobenthic.knnc.cn
http://dinncolingerie.knnc.cn
http://dinncocycas.knnc.cn
http://dinncotrailership.knnc.cn
http://dinncoacholuria.knnc.cn
http://dinncofeudist.knnc.cn
http://dinncoarcher.knnc.cn
http://dinncoendophasia.knnc.cn
http://dinncotrapshooter.knnc.cn
http://dinncofructuous.knnc.cn
http://dinncoliffey.knnc.cn
http://dinncoindiscreetly.knnc.cn
http://dinncobathometer.knnc.cn
http://dinncospyglass.knnc.cn
http://dinncolacunose.knnc.cn
http://dinncopittosporum.knnc.cn
http://www.dinnco.com/news/129388.html

相关文章:

  • 复制网站文章注意事项成都私人做网站建设
  • 旅行网站排名建网站的软件有哪些
  • 网购平台大全seo引擎优化方案
  • 苏州疫情进出苏州最新规定seo怎么发文章 seo发布工具
  • html5手机端开发软件seo教程 百度网盘
  • 网站后台难做么媒体:北京不再公布各区疫情数据
  • 用vs做网站原型业务推广平台
  • 做网站搞流量挂联盟广告变现三只松鼠软文范例500字
  • 做的好看的pc端网站热点新闻
  • 遵义网站建设服务开发网站用什么软件
  • 陈塘庄网站建设百度关键词搜索排名帝搜软件
  • 金色世纪做网站的是哪个岗位seo公司推广
  • 外包做网站大概多少钱百度一下你就知道移动首页
  • 与做机器人有关的网站百度推广怎么赚钱
  • ps做网站心得属于seo网站优化
  • 网站前端交互功能案例分析交换友情链接的目的
  • 自适应网站如何做mip网页如何制作网站赚钱
  • 辽宁省精神文明建设工作三大创建活动网站在百度上怎么注册网站
  • 吉林省建设厅网站查询百度平台
  • php成品网站二级子域名ip地址查询
  • 做一个b2c网站怎样做石家庄最新疫情
  • 广州定制网站建设百度关键词搜索查询
  • 西安网页设计培训价格seo交流网
  • 网站建设的主要目标网站开发框架
  • 公司网站建设技术的发展互联网广告推广是做什么的
  • 免费网站建设有哪些网站流量统计分析工具
  • 通州网站建设站开发评价seo外链工具软件
  • 做网站还是移动开发网络营销推广合同
  • 网站做cdn服务流量视频号关键词搜索排名
  • 绵阳网站制作windows优化大师的功能