系统常量对话框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 是已经封装好的系统常量 主要是用在控制器下面的动作当中 这样能很大的提高我们的开发效率 主要有下面的一些 手册上面都有的 ...
随机推荐
- angular 打包
ERROR in ng:///F:/IDEWorkspace/dsmc/dsmc-front-new/trunk/src/app/routes/city-manage/component-coding ...
- 浅谈CSS高度坍塌
高度坍塌情况: 当父元素没有设置高度,且子元素块都向左(右)浮动起来,那么父元素就会出现坍塌的现象. 解决办法: 在父元素包含块中加一个div: 优点:兼容性强,适合初学者. 缺点:不利于优化. 方法 ...
- shell入门基础&常见命令及用法
shell shell是一个命令解释器,实际是一个程序,/bin/bash,linux中所有的命令都由它来解释,有自己的语法 shell脚本 以.sh结尾 shell语法+linux命令 注释: 单行 ...
- spark启动原理总结
一般情况下,我们启动spark集群都是start-all.sh或者是先启动master(start-master.sh),然后在启动slave节点(start-slaves.sh),其实翻看start ...
- HDOJ:1533-Going Home(最小费用流)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1533 解题心得: 第一次写最小费用流的题,去hdoj上找了一个入门级题目,建图比较简单,用了spfa和 ...
- python的第一个程序“Hello,World”,传闻要想学好新语言....
传闻要想学好新语言,第一个程序必须是“Hello,World”...O(∩_∩)O哈哈~ 下面附上代码: # -*- coding:utf-8 -*- print("Hello,World& ...
- inner join(inner可省) 与 left join 之间的区别
关于inner join 与 left join 之间的区别,以前以为自己搞懂了,今天从前端取参数的时候发现不是预想中的结果,才知道问题出在inner join 上了. 需求是从数据库查数据,在前端以 ...
- 【转】Odoo装饰器: one装饰
one装饰器的作用是对每一条记录都执行对应的方法,相当于traditional-style中的function,无返回值! 应用举例: 定义的columns now = fields.Datetime ...
- 杭州优步uber司机第二组奖励政策
-8月9日更新- 优步杭州第二组: 定义为激活时间在2015/6/8之后2015/8/3之前的车主(以优步后台数据显示为准) 滴滴快车单单2.5倍,注册地址:http://www.udache.com ...
- 天津Uber优步司机奖励政策(12月28日到12月29日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...