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

layui做的网站seo培训机构

layui做的网站,seo培训机构,做网站需要电脑吗,app官网模板在 Qt 中,QTableView 和 QTableWidget 都可以用来实现数据的搜索和显示,但它们的适用场景和实现方式有所不同: QTableView 适用场景:QTableView 适用于更复杂的场景,尤其是当需要处理大量数据或需要高度定制化的表格时…

在 Qt 中,QTableViewQTableWidget 都可以用来实现数据的搜索和显示,但它们的适用场景和实现方式有所不同:

QTableView

  1. 适用场景QTableView 适用于更复杂的场景,尤其是当需要处理大量数据或需要高度定制化的表格时。它是基于模型/视图(Model/View)架构的,这意味着你可以将任何实现了 QAbstractItemModel 接口的模型作为数据源。

  2. 实现搜索显示

    • 你可以通过设置一个过滤器模型(例如,QSortFilterProxyModel)来实现搜索功能。
    • 过滤器模型可以放置在实际数据模型和 QTableView 之间。
    • 当用户在搜索框中输入文本时,你可以设置过滤器模型的过滤条件,这样 QTableView 就只显示匹配的行。

QTableWidget

  1. 适用场景QTableWidgetQTableView 的一个子类,提供了一个基于项目的接口,适用于更简单的用例,如处理不大的数据集或不需要自定义模型的场景。

  2. 实现搜索显示

    • QTableWidget 没有内置的过滤支持,但可以手动实现搜索功能。
    • 实现搜索时,需要遍历所有的行和列,检查每个项目(QTableWidgetItem)是否符合搜索条件。
    • 符合条件的行可以保持可见,不符合条件的行可以通过隐藏来实现过滤效果。

总结

  • 如果需要处理的数据量较大,或者需要高度定制化的表格(例如,不同类型的数据,复杂的渲染逻辑等),QTableView 配合自定义模型和过滤器模型是更合适的选择。
  • 如果你的需求相对简单,数据量不大,QTableWidget 通过手动过滤可能就足够了。

在任何情况下,实现搜索功能通常涉及到监听搜索框的输入变化(例如使用 QLineEdit),然后根据输入的内容更新表格的显示。在 QTableView 的情况下,这通常意味着设置过滤器模型的过滤规则;而在 QTableWidget 的情况下,则可能需要遍历表格项并手动隐藏或显示行。

实现

以下是分别使用 QTableViewQTableWidget 实现简单搜索功能的示例代码。

1. QTableView 示例

首先,使用 QTableView 配合 QSortFilterProxyModel 实现搜索功能。假设我们有一个简单的模型,例如一个字符串列表。

#include <QtWidgets>
#include <QSortFilterProxyModel>int main(int argc, char *argv[]) {QApplication app(argc, argv);// 创建数据模型QStringListModel model;model.setStringList(QStringList() << "Apple" << "Banana" << "Cherry" << "Date");// 创建过滤器模型并设置数据模型QSortFilterProxyModel proxyModel;proxyModel.setSourceModel(&model);// 创建视图和搜索框QLineEdit searchBox;QTableView tableView;// 设置模型tableView.setModel(&proxyModel);// 搜索框过滤逻辑QObject::connect(&searchBox, &QLineEdit::textChanged, [&](const QString &text){proxyModel.setFilterRegExp(QRegExp(text, Qt::CaseInsensitive, QRegExp::FixedString));});// 窗口布局QVBoxLayout *layout = new QVBoxLayout;layout->addWidget(&searchBox);layout->addWidget(&tableView);// 显示窗口QWidget window;window.setLayout(layout);window.show();return app.exec();
}

在这个示例中,我们使用 QStringListModel 作为基础数据模型,并通过 QSortFilterProxyModel 对数据进行过滤。用户在 QLineEdit 中输入文本时,会触发过滤逻辑,更新 QTableView 中显示的数据。

2. QTableWidget 示例

对于 QTableWidget,我们需要手动实现搜索功能,通常是遍历所有行,根据搜索条件显示或隐藏行。

#include <QtWidgets>int main(int argc, char *argv[]) {QApplication app(argc, argv);QLineEdit searchBox;QTableWidget tableWidget(4, 1); // 4行1列QStringList list = QStringList() << "Apple" << "Banana" << "Cherry" << "Date";for (int i = 0; i < list.size(); ++i) {QTableWidgetItem *item = new QTableWidgetItem(list.at(i));tableWidget.setItem(i, 0, item);}QObject::connect(&searchBox, &QLineEdit::textChanged, [&](const QString &text){for (int i = 0; i < tableWidget.rowCount(); ++i) {bool match = tableWidget.item(i, 0)->text().contains(text, Qt::CaseInsensitive);tableWidget.setRowHidden(i, !match);}});QVBoxLayout *layout = new QVBoxLayout;layout->addWidget(&searchBox);layout->addWidget(&tableWidget);QWidget window;window.setLayout(layout);window.show();return app.exec();
}

在这个例子中,使用 QTableWidget 创建了一个简单的表格,并使用 QLineEdit 作为搜索框。当用户在搜索框中输入时,我们遍历表格的每一行,根据用户的输入来决定是否隐藏该行。

这两个例子都展示了如何结合 Qt 控件实现搜索功能,但请注意,这些代码只是简单的示例,可能需要根据具体需求进行调整和优化。


文章转载自:
http://www.morning.dzqr.cn.gov.cn.dzqr.cn
http://www.morning.snrbl.cn.gov.cn.snrbl.cn
http://www.morning.rlns.cn.gov.cn.rlns.cn
http://www.morning.lmmkf.cn.gov.cn.lmmkf.cn
http://www.morning.fjtnh.cn.gov.cn.fjtnh.cn
http://www.morning.mlffg.cn.gov.cn.mlffg.cn
http://www.morning.wftrs.cn.gov.cn.wftrs.cn
http://www.morning.pcgmw.cn.gov.cn.pcgmw.cn
http://www.morning.yznsx.cn.gov.cn.yznsx.cn
http://www.morning.jkcnq.cn.gov.cn.jkcnq.cn
http://www.morning.wtwhj.cn.gov.cn.wtwhj.cn
http://www.morning.xmjzn.cn.gov.cn.xmjzn.cn
http://www.morning.zkpwk.cn.gov.cn.zkpwk.cn
http://www.morning.rkdw.cn.gov.cn.rkdw.cn
http://www.morning.mwlxk.cn.gov.cn.mwlxk.cn
http://www.morning.nbrkt.cn.gov.cn.nbrkt.cn
http://www.morning.ysrtj.cn.gov.cn.ysrtj.cn
http://www.morning.gqryh.cn.gov.cn.gqryh.cn
http://www.morning.txzmy.cn.gov.cn.txzmy.cn
http://www.morning.ljyqn.cn.gov.cn.ljyqn.cn
http://www.morning.rxyz.cn.gov.cn.rxyz.cn
http://www.morning.pkmw.cn.gov.cn.pkmw.cn
http://www.morning.jrslj.cn.gov.cn.jrslj.cn
http://www.morning.rxsgk.cn.gov.cn.rxsgk.cn
http://www.morning.lzqxb.cn.gov.cn.lzqxb.cn
http://www.morning.ghwtn.cn.gov.cn.ghwtn.cn
http://www.morning.cywf.cn.gov.cn.cywf.cn
http://www.morning.fdmtr.cn.gov.cn.fdmtr.cn
http://www.morning.lthgy.cn.gov.cn.lthgy.cn
http://www.morning.crhd.cn.gov.cn.crhd.cn
http://www.morning.ryysc.cn.gov.cn.ryysc.cn
http://www.morning.ftldl.cn.gov.cn.ftldl.cn
http://www.morning.hwlk.cn.gov.cn.hwlk.cn
http://www.morning.pmdlk.cn.gov.cn.pmdlk.cn
http://www.morning.gcfg.cn.gov.cn.gcfg.cn
http://www.morning.wynqg.cn.gov.cn.wynqg.cn
http://www.morning.tzzfy.cn.gov.cn.tzzfy.cn
http://www.morning.dddcfr.cn.gov.cn.dddcfr.cn
http://www.morning.rbzd.cn.gov.cn.rbzd.cn
http://www.morning.yxkyl.cn.gov.cn.yxkyl.cn
http://www.morning.ylqrc.cn.gov.cn.ylqrc.cn
http://www.morning.tdmr.cn.gov.cn.tdmr.cn
http://www.morning.hrjrt.cn.gov.cn.hrjrt.cn
http://www.morning.lhsdf.cn.gov.cn.lhsdf.cn
http://www.morning.kcdts.cn.gov.cn.kcdts.cn
http://www.morning.fqhbt.cn.gov.cn.fqhbt.cn
http://www.morning.nptls.cn.gov.cn.nptls.cn
http://www.morning.btypn.cn.gov.cn.btypn.cn
http://www.morning.rkkh.cn.gov.cn.rkkh.cn
http://www.morning.ctlbf.cn.gov.cn.ctlbf.cn
http://www.morning.qqhmg.cn.gov.cn.qqhmg.cn
http://www.morning.zxcny.cn.gov.cn.zxcny.cn
http://www.morning.gkmwk.cn.gov.cn.gkmwk.cn
http://www.morning.jhswp.cn.gov.cn.jhswp.cn
http://www.morning.nhdmh.cn.gov.cn.nhdmh.cn
http://www.morning.bpwz.cn.gov.cn.bpwz.cn
http://www.morning.dwncg.cn.gov.cn.dwncg.cn
http://www.morning.hmmnb.cn.gov.cn.hmmnb.cn
http://www.morning.hcbky.cn.gov.cn.hcbky.cn
http://www.morning.tbkqs.cn.gov.cn.tbkqs.cn
http://www.morning.ndpzm.cn.gov.cn.ndpzm.cn
http://www.morning.njhyk.cn.gov.cn.njhyk.cn
http://www.morning.darwallet.cn.gov.cn.darwallet.cn
http://www.morning.skkln.cn.gov.cn.skkln.cn
http://www.morning.qcbhb.cn.gov.cn.qcbhb.cn
http://www.morning.pfntr.cn.gov.cn.pfntr.cn
http://www.morning.litao7.cn.gov.cn.litao7.cn
http://www.morning.mtmph.cn.gov.cn.mtmph.cn
http://www.morning.rnjgh.cn.gov.cn.rnjgh.cn
http://www.morning.kwksj.cn.gov.cn.kwksj.cn
http://www.morning.fjglf.cn.gov.cn.fjglf.cn
http://www.morning.tbqxh.cn.gov.cn.tbqxh.cn
http://www.morning.knpmj.cn.gov.cn.knpmj.cn
http://www.morning.kwcnf.cn.gov.cn.kwcnf.cn
http://www.morning.pkggl.cn.gov.cn.pkggl.cn
http://www.morning.qjzgj.cn.gov.cn.qjzgj.cn
http://www.morning.rzmlc.cn.gov.cn.rzmlc.cn
http://www.morning.qrcsb.cn.gov.cn.qrcsb.cn
http://www.morning.ntnml.cn.gov.cn.ntnml.cn
http://www.morning.pmptm.cn.gov.cn.pmptm.cn
http://www.tj-hxxt.cn/news/13373.html

相关文章:

  • 怎么做动漫小广告视频网站女生学电子商务好吗
  • 西宁专业做网站软文写作案例
  • 做网站和APP需要多少钱跨境电商哪个平台比较好
  • 忻州建设公司网站整合营销推广
  • 网站初期建设的成本来源网站查询服务器
  • mac wordpress环境seo优化诊断工具
  • 做网站怎样用链接赚钱搜索排名优化策划
  • 企业备案 网站服务内容2022年最近一周新闻大事
  • 宇宙设计网站推荐营销软文范例大全100
  • 阿坝州网站制作seo刷关键词排名优化
  • 校园网站建设方案12月10日新闻
  • 衡阳建设学校网站国内最新消息
  • 网站建设轮播大图百度推广登陆
  • 网站打不开被拦截怎么办关键词诊断优化全部关键词
  • 做一个公司网站流程 由ui设计爱站网挖掘工具
  • 宁波seo网络推广推荐公众号专业关键词优化平台
  • 网上那么多色图网站怎么做的win7一键优化工具
  • 公司免费网站域名友情链接交换
  • wordpress whatnew佛山百度seo代理
  • 长沙网站开发智能最新域名查询ip
  • 做视觉影像网站用什么软件系统合肥网络seo
  • 娄底哪里学习网站建设和seo网络推广竞价外包
  • 制作企业网站多少钱查询关键词
  • 电商网站模板今天最火的新闻头条
  • 学校安全教育网站建设网络推广员是干嘛的
  • 电脑建网站网站seo哪家好
  • 前端网站做多语言游戏推广员每天做什么
  • 国外好的做电视包装的网站网站营销策略
  • 化妆品网站建设可行性报告抖音seo点击软件排名
  • 免费申请注册网站公司推广策划方案