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

QTableWidget——编辑单元格

文章目录

  • 前言
    • 熟悉QTableWiget,通过实现单元格的合并、拆分、通过编辑界面实现表格内容及属性的配置、实现表格的粘贴复制功能熟悉QTableWiget的属性
  • 一、[单元格的合并、拆分](https://blog.csdn.net/qq_15672897/article/details/134476530?spm=1001.2014.3001.5502)
  • 二、表格内容及属性设置
    • 1.效果图
    • 2.主要代码
  • 三、表格的粘贴复制功能


前言

熟悉QTableWiget,通过实现单元格的合并、拆分、通过编辑界面实现表格内容及属性的配置、实现表格的粘贴复制功能熟悉QTableWiget的属性

一、单元格的合并、拆分

二、表格内容及属性设置

1.效果图

通过双击单元格进入编辑界面
在这里插入图片描述
在这里插入图片描述

2.主要代码

编辑界面的代码如下:

void CItemTypeDialog::init()
{m_bold = 0;m_pFontColorDlg = new  QColorDialog(this);mp_bgdColorDialog = new  QColorDialog(this);connect(m_pUi->pButtonOk,SIGNAL(clicked()),this,SLOT(onOk()));connect(m_pUi->pButtonCancel,SIGNAL(clicked()),this,SLOT(onCancel()));connect(m_pUi->pFontColorBtn, &QPushButton::clicked, this, &CItemTypeDialog::showColorDialog);connect(m_pUi->pBackgroundBtn, &QPushButton::clicked, this, &CItemTypeDialog::showColorDialog);connect(m_pFontColorDlg, &QColorDialog::currentColorChanged, this, &CItemTypeDialog::colorValue);connect(mp_bgdColorDialog, &QColorDialog::currentColorChanged, this, &CItemTypeDialog::bgdcolorValue);sprintf(m_bgdcolorarr, "#%s%s%s","ff","ff","ff");sprintf(m_fontcolorarr, "#%s%s%s","00","00","00");
}void CItemTypeDialog::setType(TableItemInfor *pItem)
{m_pItem = pItem;m_pUi->textEdit->setText(m_pItem->data);QString str = QString::fromUtf8(m_pItem->style);if (!(str.isEmpty())){QStringList stylelist = str.split(",");m_pUi->pFontComboBox->setCurrentText(stylelist.at(0));//字体m_pUi->pFontSizeComboBox->setCurrentText(stylelist.at(1));//字号//是否加粗m_pUi->boldCheckBox->setChecked(stylelist.at(2).toInt());//字体颜色strcpy(m_fontcolorarr, stylelist.at(3).toUtf8());m_pUi->pFontColorBtn->setStyleSheet(QString::fromUtf8("background-color: %1;").arg(stylelist.at(3)));QColor color(stylelist.at(3));m_pFontColorDlg->setCurrentColor(color);//背景颜色strcpy(m_bgdcolorarr, stylelist.at(4).toUtf8());m_pUi->pBackgroundBtn->setStyleSheet(QString::fromUtf8("background-color: %1;").arg(stylelist.at(4)));QColor bgcolor(stylelist.at(4));mp_bgdColorDialog->setCurrentColor(bgcolor);}}
void CItemTypeDialog::showColorDialog()
{QToolButton* tb = qobject_cast<QToolButton*>(sender());if (tb == m_pUi->pFontColorBtn){m_pFontColorDlg->show();}else if (tb == m_pUi->pBackgroundBtn){mp_bgdColorDialog->show();}
}
void CItemTypeDialog::onOk()
{getStyle();accept();
}void CItemTypeDialog::onCancel()
{reject();
}void CItemTypeDialog::getStyle()
{m_pItem->data = m_pUi->textEdit->toPlainText();sprintf(m_pItem->style, "%s,%d,%d,%s,%s", m_pUi->pFontComboBox->currentText().toStdString().c_str(),m_pUi->pFontSizeComboBox->currentText().toInt(), m_bold, m_fontcolorarr, m_bgdcolorarr);
}void CItemTypeDialog::colorValue(const QColor& color)
{int r, g, b, a;color.getRgb(&r, &g, &b, &a);QString hexRed = QString::number(r, 16);if (hexRed == "0"){hexRed = "00";}QString hexGreen = QString::number(g, 16);if (hexGreen == "0"){hexGreen = "00";}QString hexBlue = QString::number(b, 16);if (hexBlue == "0"){hexBlue = "00";}sprintf(m_fontcolorarr, "#%s%s%s", hexRed.toStdString().c_str(), hexGreen.toStdString().c_str(), hexBlue.toStdString().c_str());m_pUi->pFontColorBtn->setStyleSheet(QString::fromUtf8("background-color: %1;").arg(QString::fromUtf8(m_fontcolorarr)));
}void CItemTypeDialog::bgdcolorValue(const QColor &color)
{int r, g, b, a;color.getRgb(&r, &g, &b, &a);QString hexRed = QString::number(r, 16);if (hexRed == "0"){hexRed = "00";}QString hexGreen = QString::number(g, 16);if (hexGreen == "0"){hexGreen = "00";}QString hexBlue = QString::number(b, 16);if (hexBlue == "0"){hexBlue = "00";}sprintf(m_bgdcolorarr, "#%s%s%s", hexRed.toStdString().c_str(), hexGreen.toStdString().c_str(), hexBlue.toStdString().c_str());m_pUi->pBackgroundBtn->setStyleSheet(QString::fromUtf8("background-color: %1;").arg(QString::fromUtf8(m_bgdcolorarr)));
}

三、表格的粘贴复制功能

功能待完善!

http://www.lryc.cn/news/241266.html

相关文章:

  • 编译QT Mysql库并集成使用
  • 利用企业被执行人信息查询API保障商业交易安全
  • 【深度学习】P1 深度学习基础框架 - 张量 Tensor
  • vue2 识别页面参数中的html
  • matlab 一些画图法总结(持续更新)
  • MDK AC5和AC6是什么?在KEIL5中添加和选择ARMCC版本
  • 杰发科技AC7801——EEP内存分布情况
  • 【mybatis注解实现条件查询】
  • 【广州华锐互动】VR线上课件制作软件满足数字化教学需求
  • MySQL 中 DELETE 语句中可以使用别名么?
  • flutter创建不同样式的按钮,背景色,边框,圆角,圆形,大小都可以设置
  • 【C++】标准模板库STL作业(其二)
  • 基于SpringBoot+Redis实现点赞/排行榜功能,可同理实现收藏/关注功能,可拓展实现共同好友/共同关注/关注推送功能
  • AI“胡说八道”?怎么解?
  • [SIGGRAPH-23] 3D Gaussian Splatting for Real-Time Radiance Field Rendering
  • 大话设计模式C++实现
  • IT 领域中的主要自动化趋势
  • 使用Python解析CAN总线
  • DevExpress中文教程 - 如何在macOS和Linux (CTP)上创建、修改报表(下)
  • RAID的应用场景以及优缺点
  • java SpringCloud版本b2b2c鸿鹄云商平台全套解决方案 小程序商城免费搭建
  • [Linux] shell脚本的函数和数组
  • 万宾科技智能井盖的效果怎么样?
  • nvm切换版本之后npm用不了
  • 【elementui】el-popover在列表里循环使用,取消的doClose无效解决办法
  • 【php】解决加载速度慢导出超时问题记录
  • postgresql安装fdw扩展
  • 反爬虫机制与反爬虫技术(二)
  • Grails 启动
  • 2023年亚太地区数学建模大赛 问题A