系统常量对话框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 是已经封装好的系统常量 主要是用在控制器下面的动作当中 这样能很大的提高我们的开发效率 主要有下面的一些 手册上面都有的 ...
随机推荐
- Python 简单购物车
product_list =[ ('huawei',3000), ('hongmiNote3',3000), ('sanxing',2600), ('ThinkPad870',15000), ('Ip ...
- 常见IE8兼容性问题及解决
1.css3媒体查询 IE8不支持媒体查询 解决:respond.js,在页面中所有css文件的引用位置之后引用Respond.js 2.HTML5新标签 IE8不支持H5新标签 解决:html5sh ...
- 帝国cms发布信息时替换正文IMG图片标签里的ALT内容
帝国cms发布信息时替换正文IMG图片标签里的ALT内容 在 e/class/userfun.php 里面增加 //替换正文IMG里的ALT内容 function user_imgalt($mid,$ ...
- Bigdata--hadoop系列安装
Date:20180827 Monday 目前市场hadoop主流版本是2.7.x系列,下面我们就以hadoop-2.7.3为例进行安装 安装前准备: 1.操作系统:cetos(6和7) 2.java ...
- django配置虚拟环境-1
目录 安装python 使用venv虚拟环境 使用Virtualenv虚拟环境 ### Windows安装 方案一 方案二 Linux安装 其他命令 安装django 安装python https:/ ...
- 关于mysql 8.0.13zip包安装
mysql 8.0.13默认有一个data文件夹,这个文件夹得删了,不然安装服务时候会有日志文件提示报错: Failed to find valid data directory. Data Dict ...
- 关于条件约束问题的无偏差统计——一个偏差控制型生成器(Unbiased Statistics of a Constraint Satisfaction Problem – a Controlled-Bias Generator——by Denis Berthier)
论文地址:https://hal.archives-ouvertes.fr/hal-00641955 Unbiased Statistics of a Constraint Satisfaction ...
- java基础之while语句的练习
计算1-100,7的倍数的数的总和 代码如下: public class Demo1 { public static void main(String[] args) { int num=1; int ...
- 成都Uber优步司机奖励政策(2月19日)
滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...
- CF 1051 F. The Shortest Statement
F. The Shortest Statement http://codeforces.com/contest/1051/problem/F 题意: n个点,m条边的无向图,每次询问两点之间的最短路. ...