功能待完善

#ifndef MYMAINWINDOW_H
#define MYMAINWINDOW_H #include <QMainWindow>
#include <QTableView>
#include <QStandardItemModel>
#include <QItemSelectionModel>
#include <QMenu> #define FixedColumnCount 8 class MyMainWindow : public QMainWindow
{
Q_OBJECT private:
QTableView *_tableView;
QStandardItemModel *_standardItemModel;
QItemSelectionModel *_itemSelectionModel;
QMenu *_menu; public:
MyMainWindow(QWidget *parent = nullptr);
~MyMainWindow();
bool eventFilter(QObject* obj, QEvent *event);
void createActions(const QStringList &textList);
void subset(); public slots:
void setTextSlot(); }; #endif // MYMAINWINDOW_H
#include "mymainwindow.h"
#include <QEvent> MyMainWindow::MyMainWindow(QWidget *parent) : QMainWindow(parent)
{
// 界面
_tableView = new QTableView();
setCentralWidget(_tableView);
resize(, ); // model/view
_standardItemModel = new QStandardItemModel(, FixedColumnCount, this);
_itemSelectionModel = new QItemSelectionModel(_standardItemModel); _tableView->setModel(_standardItemModel);
_tableView->setSelectionModel(_itemSelectionModel);
_tableView->setSelectionMode(QAbstractItemView::ExtendedSelection);
_tableView->setSelectionBehavior(QAbstractItemView::SelectItems);
_tableView->installEventFilter(this); _menu = new QMenu(this);
} MyMainWindow::~MyMainWindow()
{ } bool MyMainWindow::eventFilter(QObject *obj, QEvent *event)
{
if(obj == _tableView && event->type() == QEvent::ContextMenu)
{
if(_tableView->currentIndex().isValid()==true)
{
_menu->exec(cursor().pos());
}
} return QWidget::eventFilter(obj, event);
} // 在tableview上动态创建actions
void MyMainWindow::createActions(const QStringList &textList)
{
for(int i = ; i < textList.size(); i++)
{
QString text = textList.at(i);
_menu->addAction(text, this, SLOT(setTextSlot()));
}
} void MyMainWindow::setTextSlot()
{
// 获取action
QAction *action = static_cast<QAction *>(sender());
QString text = action->text(); // 获取选中item,通过以下方式,或者通过QAbstractItemview的selectedIndexes方法
QModelIndexList indexList = _itemSelectionModel->selectedIndexes(); // 设置model
for(int i = ; i < indexList.size(); i++)
{
QModelIndex index = indexList.at(i);
_standardItemModel->setData(index, text);
}
} // 求多个字符串序列的子集
void MyMainWindow::subset()
{ }
#include "mymainwindow.h"
#include <QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
MyMainWindow w;
w.show(); return a.exec();
}

1.求子集,2.动态创建action的更多相关文章

  1. jQuery 绑定事件到动态创建的元素上

    在进入主题之前,我们先来看一个前台页面经常用到的功能:点击页面输入框时自动选择其中文本. 很容易想到利用输入框的focus事件,当输入框获得焦点时,再调用jQuery的select()方法. Okay ...

  2. Android实现多页左右滑动效果,支持子view动态创建和cache

    要实现多页滑动效果,主要是需要处理onTouchEvent和onInterceptTouchEvent,要处理好touch事件的子控件和父控件的传递问题. 滚动控制可以利用android的Scroll ...

  3. 使用dxNavBar动态创建应用程序菜单

    一.如何动态创建dxNavBar内容: function TMain.GetAcitonByCaption(const aCategory,aCaption: string): Integer; va ...

  4. BroadcastReceiver接收电量变化的广播-------在代码中动态创建接受者

    本例为动态创建广播接收者即不是在AndroidManifest.xml文件中定义的广播接收着 代码: package com.qf.broadcastreceiver01; import androi ...

  5. js动态创建Form表单并提交

    javascript动态创建Form表单和表单项,然后提交表单请求,最后删除表单,代码片段如下(Firefox测试通过): var dlform = document.createElement('f ...

  6. js动态创建和删除option

    1.动态创建select function createSelect(){           var mySelect = document.createElement("select&q ...

  7. 动态创建selectjs 操作select和option

    1.动态创建select function createSelect(){ var mySelect = document.createElement("select"); myS ...

  8. jQuery动态创建form表单并提交到后台(携带一定的数据进行页面跳转)

    今天遇到这么一个需求,携带一个编号一个名字跳转到另一个JSP页面,直接页面跳转(get携带数据)的话不太安全,于是想到到后台转发一下. 第一种:直接以表单提交方式的进行 JS代码: var form ...

  9. ArcGIS api for javascript——动态创建图层列表

    描述 本例循环地图服务里的所有图层并增加每个图层到一个带checkbox的列表,checkbox能设置图层的显示或隐藏.动态创建列表的优势是所有的图层都会包含在列表中,即使服务器管理员删除或增加了图层 ...

随机推荐

  1. IDEA中maven工程打包时使用跳过test模式

  2. AngularJS1.X指令

    <!DOCTYPE html> <html ng-app='myApp'> <head> <meta charset="utf-8"> ...

  3. [Codeforces #608 div2]1271D Portals

    Description You play a strategic video game (yeah, we ran out of good problem legends). In this game ...

  4. 嵊州普及Day5T4

    题意:两个1,每次可将一个*k,一个*K2,n个问题,问能否达成x,y? 思路:只有将x,y相乘为3次方时,才可能.并且相乘的三次方一定要是x,y的因子. 下面证明:3次方易证,因为对每个k,都会乘三 ...

  5. 关于pgsql 几个操作符的效率测试比较

    关于pgsql 几个操作符的效率测试比较1. json::->> 和 ->> 测试方法:单次运行100次,运行10个单次取平均时间.测试结果:->> 效率高 5% ...

  6. GNS3 模拟免费ARP

    R2 : conf t int f0/0 no shutdown ip add 192.168.1.254 255.255.255.0 end R1 : conf t int f0/0 no shut ...

  7. CRC校验算法详解

    CRC(Cyclic Redundancy Check)循环冗余校验是常用的数据校验方法,讲CRC算法的文章很多,之所以还要写这篇,是想换一个方法介绍CRC算法,希望能让大家更容易理解CRC算法. 先 ...

  8. Windows下 dmp文件的产生

    一.windows下的崩溃捕获windows程序当遇到异常,没有try-catch或者try-catch也无法捕获到的异常时,程序就会自动退出.windows系统默认是不产生程序dmp文件的.dump ...

  9. 0203 生成mysql的数据库的数据字典

    原理 项目的数据库字典表是一个很重要的文档.通过此文档可以清晰的了解数据表结构及开发者的设计意图. 通常为了方便我都是直接在数据库中建表,然后通过工具导出数据字典. 在Mysql数据库中有一个info ...

  10. windows电脑安装python教程

    1 版本选择 2.x版本将慢慢退出历史的舞台,建议你从3.x开始学习,本教程所使用的python版本是3.6 2 下载安装包 进入官网下载页面 https://www.python.org/downl ...