系统常量对话框QT实现
1.运行结果:

2.代码
main.cpp
#include "constantdiag.h"
#include <QtWidgets/QApplication> int main(int argc, char *argv[])
{
QApplication a(argc, argv);
constantDiag w;
w.show();
return a.exec();
}
constantDialog.h
#ifndef CONSTANTDIAG_H
#define CONSTANTDIAG_H #include <QtWidgets/QWidget>
#include <QHBoxLayout>
#include <QPushButton>
#include <QStandardItemModel>
#include <QTableView>
#include <QVBoxLayout>
#include <QHeaderView>
#include <QLabel> class ComboDelegate; class constantDiag : public QWidget
{
Q_OBJECT public:
constantDiag(QWidget *parent = );
~constantDiag(); public slots:
void addConstant();
void reduceConstant(); private:
QHBoxLayout *secondHLayout;
QPushButton *btnConstantPlus;
QPushButton *btnConstantMinus;
QStandardItemModel *model;
QTableView *tableview;
QVBoxLayout *wholeLayout;
QHBoxLayout *thirdHLayout;
QPushButton *btnOk;
QPushButton *btnCancel;
QHBoxLayout *topLayout;
QLabel *titleLabel;
QVBoxLayout *wholeVLayout;
ComboDelegate *comboDelegate;
}; #endif // CONSTANTDIAG_H #ifndef COMBODELEGATE_H
#define COMBODELEGATE_H #include <QItemDelegate> class ComboDelegate : public QItemDelegate
{
Q_OBJECT
public:
ComboDelegate(QObject *parent = ); QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
void setEditorData(QWidget *editor, const QModelIndex &index) const;
void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const;
}; #endif // COMBODELEGATE_H
constantDialog.cpp
#include "constantdiag.h" constantDiag::constantDiag(QWidget *parent)
: QWidget(parent)
{
setWindowTitle(QString::fromLocal8Bit("系统常量"));
resize(,); wholeLayout = new QVBoxLayout(parent); secondHLayout = new QHBoxLayout();
secondHLayout->addStretch(); btnConstantPlus = new QPushButton;
btnConstantPlus->setText("+");
secondHLayout->addWidget(btnConstantPlus); btnConstantMinus = new QPushButton;
btnConstantMinus->setText("-");
secondHLayout->addWidget(btnConstantMinus); secondHLayout->setStretch(,);
secondHLayout->setStretch(,);
secondHLayout->setStretch(,); wholeLayout->addLayout(secondHLayout); model = new QStandardItemModel(,);
model->setHeaderData(,Qt::Horizontal,QString::fromLocal8Bit("名称"));
model->setHeaderData(,Qt::Horizontal,QString::fromLocal8Bit("值"));
model->setHeaderData(,Qt::Horizontal,QString::fromLocal8Bit("单位"));
tableview = new QTableView(parent);
tableview->setModel(model);
tableview->verticalHeader()->setVisible(false);
tableview->horizontalHeader()->setSectionResizeMode(, QHeaderView::Stretch);
tableview->horizontalHeader()->setSectionResizeMode(, QHeaderView::Stretch);
tableview->horizontalHeader()->setSectionResizeMode(, QHeaderView::Stretch);
comboDelegate = new ComboDelegate;
tableview->setItemDelegateForColumn(,comboDelegate);
//tableview->verticalHeader()->setSectionResizeMode(0,QHeaderView::Stretch);
//tableview->verticalHeader()->setSectionResizeMode(1,QHeaderView::Stretch); wholeLayout->addWidget(tableview); thirdHLayout = new QHBoxLayout;
thirdHLayout->addStretch(); btnOk = new QPushButton;
btnOk->setText(QString::fromLocal8Bit("确定"));
btnCancel = new QPushButton;
btnCancel->setText(QString::fromLocal8Bit("取消"));
thirdHLayout->addWidget(btnOk);
thirdHLayout->addWidget(btnCancel); thirdHLayout->setStretch(,);
thirdHLayout->setStretch(,);
thirdHLayout->setStretch(,); wholeLayout->addLayout(thirdHLayout);
//wholeLayout->setSizeConstraint(QLayout::SetFixedSize);
//wholeLayout->setStretchFactor(secondHLayout, 1);
//wholeLayout->setStretchFactor(tableview, 2);
//wholeLayout->setStretchFactor(thirdHLayout, 1); setLayout(wholeLayout); connect(btnConstantPlus,SIGNAL(clicked()),this,SLOT(addConstant()));
connect(btnConstantMinus,SIGNAL(clicked()),this,SLOT(reduceConstant()));
} constantDiag::~constantDiag()
{ } void constantDiag::addConstant()
{
int row = model->rowCount();
model->insertRow(row);
} void constantDiag::reduceConstant()
{
int row = model->rowCount();
model->removeRow(--row);
} #include <QComboBox> ComboDelegate::ComboDelegate(QObject *parent) :
QItemDelegate(parent)
{
} QWidget *ComboDelegate::createEditor(QWidget *parent,const QStyleOptionViewItem &/*option*/,const QModelIndex &/*index*/) const
{
QComboBox *editor = new QComboBox(parent);
//editor->lineEdit()->setAlignment(Qt::AlignCenter);
editor->setEditable(true);
//editor->setStyleSheet("QComboBox{border:1px solid gray;}""QComboBox QAbstractItemView::item{height:25px;}"); //editor->setView(new QListView());
editor->addItem("N");
editor->addItem("m");
editor->addItem("m/s");
editor->installEventFilter(const_cast<ComboDelegate*>(this));
return editor;
} void ComboDelegate::setEditorData(QWidget *editor,const QModelIndex &index) const
{
QString str =index.model()->data(index).toString();
QComboBox *box = static_cast<QComboBox*>(editor);
int i=box->findText(str);
box->setCurrentIndex(i);
} void ComboDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const
{
QComboBox *box = static_cast<QComboBox*>(editor);
QString str = box->currentText();
model->setData(index,str);
} void ComboDelegate::updateEditorGeometry(QWidget *editor,const QStyleOptionViewItem &option, const QModelIndex &/*index*/) const
{
editor->setGeometry(option.rect);
}
系统常量对话框QT实现的更多相关文章
- ThinPHP命名空间,连接数据库是要修改的配置文件,Model数据模型层,跨控制器调用,如何获取系统常量信息,
一.命名空间(主要是为了实现自动加载类) *命名空间(相当于虚拟的目录),为了让类有一个统一的文件夹来管理(可以自动加载'类'),每个文件都要有命名空间*tp如何做命名空间:*TP框架下有一个初始命名 ...
- thinkphp系统常量与自定义常量
----------------------------------------Action中使用的系统常量 ----------------------------------------THINK ...
- PHPCMS系统常量
以下系统常量全局可用 APP_PATH 动态程序路径 WEB_PATH 网站根路径 JS_PATH JS路径 CSS_PATH CSS路径 IMG_PATH 图片路径 CACHE_PATH 缓 ...
- phpcms标签使用 —— 系统常量
以下系统常量全局可用 1 2 3 4 5 6 7 8 9 10 11 12 13 CACHE_PATH 缓存文件夹地址 SITE_PROTOCOL 主机协议 SITE_URL 当前访问的主机名 HTT ...
- Paip.最佳实践-- Buildin variale 内建变量 ,魔术变量,预定义变量,系统常量,系统变量 1
Paip.最佳实践-- Buildin variale 内建变量 ,魔术变量,预定义变量,系统常量,系统变量 1.1.1 C++内建变量(__LINE__).... 1.1.2 ...
- (转)Thinkphp系统常量 演示
Thinkphp2.1框架内置了许多系统常量, 具体如下: __ROOT__ : 网站根目录地址 __APP__ : 当前项目(入口文件)地址 __URL__ : 当前模块地址 __ACTION__ ...
- [php基础]PHP环境变量$_SERVER和系统常量详细说明
在PHP网站开发中,为了满足网站的需要,时常需要对PHP环境变量进行设置和应用,在虚拟主机环境下,有时我们更需要通过PHP环境变量操作函数来对PHP环境变量值进行设置.为此我们有必要对PHP环境变量先 ...
- php的系统常量
认识一下系统常量 系统常量是PHP已经定义好的常量,我们可以直接拿来使用,常见的系统常量有: (1)__FILE__ :php程序文件名.它可以帮助我们获取当前文件在服务器的物理位置. (2)__LI ...
- tp系统常量定义
(2013-03-06 14:16:31) 转载▼ 标签: it 是已经封装好的系统常量 主要是用在控制器下面的动作当中 这样能很大的提高我们的开发效率 主要有下面的一些 手册上面都有的 ...
随机推荐
- wireshark利用正则表达式过滤http协议中的jpg png zip等无用的数据包
主要工具:小度随身wifi热点 + wireshark抓包工具.(强烈不建议使用360的产品,非常垃圾,而且干扰代理#墙IP,搞得你不能***) 利用wireshark这个强大的协议分析利器.去分析某 ...
- 7. CSS装饰网页的样式
CSS中有哪些用来装饰网页的样式呢?在这里我们对一些常用的样式做了总结. 字体样式 /* * 一般样式书写 */ .font_style_1{ font-family: "华文行楷" ...
- mongodb数据的导出和导入
mongo导出表说明: root@827995de7c7f:/# mongoexport --help Usage: mongoexport <options> Export data f ...
- 闰年相关的问题v3.0——计算有多少闰年
# include<stdio.h>int main(){ int a,b,i; int sum = 0; printf("Input your birth year:" ...
- 如何将github项目上传至gitlab
一.修改远程分支关联 删除远程分支关联 将指向github的远程分支关联关系删除 git remote rm origin 添加新的远程分支关联 新的remote地址指向gitlab相应地址 git ...
- HyperLedger Fabric 1.4 生产环境使用ca生成msp和tls(12)
在上一章:Fabric kafka生产环境部署的基础上部署Fabric CA,使用Fabric CA进行生成公私钥和证书等文件,全部替换cryptogen工具,包括生成TLS相关的私钥和证书等文件. ...
- Java基础—IO小结(二)缓冲流与其它流的使用
一.缓冲流的使用 每个字节流都有对应的缓冲流: BufferedInputStream / BufferedOutputStream 构造器: 方法摘要与对应节点流类似 使用缓冲流实现文件复制:实际中 ...
- 【BZOJ2286】消耗战(虚树,动态规划)
[BZOJ2286]消耗战(虚树,动态规划) 题面 BZOJ Description 在一场战争中,战场由n个岛屿和n-1个桥梁组成,保证每两个岛屿间有且仅有一条路径可达.现在,我军已经侦查到敌军的总 ...
- 成都Uber优步司机奖励政策(1月29日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- Mac iTem2 自动登录服务器配置
假设你要连接的服务器地址为123.123.123.123,端口号为8888,用户名为root,密码为mimamima 编写shell文件"login_server.sh",并放置于 ...