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

两个网站做响应式网站/营销模式

两个网站做响应式网站,营销模式,网站建设总体设计,湖北省工程建设信息官方网站文章目录前言新建项目可视化布局控件控件选择修改控件属性设置伙伴关系与TAB顺序窗体布局编写程序hellodialog.hhellodialog.cppmian.cui_hellodialog.h前言 本文主要参考资料&#xff1a; Jasmin Blanchette<C GUI QT4编程(第二版)> 电子工业出版社 本文主要实现功能…

文章目录

  • 前言
  • 新建项目
  • 可视化布局控件
      • 控件选择
      • 修改控件属性
      • 设置伙伴关系与TAB顺序
      • 窗体布局
  • 编写程序
      • hellodialog.h
      • hellodialog.cpp
      • mian.c
      • ui_hellodialog.h

前言

本文主要参考资料:

  • Jasmin Blanchette<C++ GUI QT4编程(第二版)> 电子工业出版社

本文主要实现功能为:编写一个对话框。其运行效果如下图所示:
在这里插入图片描述
本文使用软件对应版本为:

  • QT creator4.4.1
  • QT4.8.7
  • MinGW 4.8.2

新建项目

  1. 快捷键:Ctrl+Shift+N,或者选择文件-新建项目或文件。出现下图
    在这里插入图片描述
  2. 如上图,选择Application-> QT widgets Application。然后点击choose,得到如下界面。
    在这里插入图片描述
  3. 如上图,在名称一栏填入项目名称,如Demo。在创建路径中填入项目地址。点击下一步按钮。
    在这里插入图片描述
  4. 继续点击下一步。因为我们创建的是对话框,所以在基类选项中选择QDialog。类名自己根据实际定义,这里填写为HelloDialog。其余文件名称会自动修改。
    在这里插入图片描述
  5. 点击下一步。
    在这里插入图片描述
  6. 此页面默认,选择完成。
    在这里插入图片描述

可视化布局控件

首先,双击hellodialog.ui进行可视化布局。
在这里插入图片描述

控件选择

选择以下三种控件,并大致进行排列。

  • Dialog Button Box
  • Line Edit
  • Label
    在这里插入图片描述

修改控件属性

  1. 单击TextLabel,并修改text属性为“名称(&N)“。
    在这里插入图片描述
  2. 单击窗体,修改窗体的标题为:“你好!”。
    在这里插入图片描述

设置伙伴关系与TAB顺序

在这里插入图片描述
因为此对话框TAB选项只有一个,所以,不再演示。其设置方式在上图已标注。单击“Edit Buddies”。点击名称(&N)标签,且拖住到lineEdit控件,在放鼠标。此时,会通过蓝色箭头将两者连接起来。表明伙伴关系建立成功。
在这里插入图片描述
此时,可以看到“&”字符消失不见。&标记是用来标记快捷键。此时表明当程序运行时,键盘输入ALT+N,lineEidt就会被选中。
最后,按F3或者单击“编辑窗口”退出编辑伙伴关系。

窗体布局

  1. 同时选择label和lineEdit,且单击水平布局
    在这里插入图片描述
  2. 同理,将单击对话框HelloDialog。并单击竖直布局
    在这里插入图片描述
  3. 最后自动调整对话框大小。单击HelloDialog,且单击调整大小
    在这里插入图片描述

至此,可视化布局部分完成,Ctrl+S保存数据。

编写程序

在新建项目的时候,Qt Creator 已经创建了对话框的头文件和c文件,以及显示对话框的main函数。我们编写程序只要基于以上修改即可。注释不祥部分,可以参考上篇博客<QT第一篇——创建对话框>或者参考本文的参考文献。

hellodialog.h

#ifndef HELLODIALOG_H
#define HELLODIALOG_H#include <QDialog>namespace Ui {
class HelloDialog;
}//当程序编译的时候,会自动根据ui文件生成布局相关的类Ui_HelloDialog。此处声明的类,及Ui::HelloDialog为其空子类。class HelloDialog : public QDialog
{Q_OBJECTpublic:explicit HelloDialog(QWidget *parent = 0);//构造函数~HelloDialog();//析构函数private slots:void on_lineEdit_textChanged();//私有槽函数,当lineEdit控件发射textChanged信号时,自动调用此槽函数。private:Ui::HelloDialog *ui;//声明一个私有ui布局相关对象
};#endif // HELLODIALOG_H

hellodialog.cpp

#include "hellodialog.h"
#include "ui_hellodialog.h"#include<QtGui>HelloDialog::HelloDialog(QWidget *parent) :QDialog(parent),//调用父类构造函数ui(new Ui::HelloDialog)//创建一个ui对象
{//初始化窗体ui->setupUi(this);//初始化窗体,载入窗体布局,自动调用命名符合规则的槽函数。//ButtonBox中OK键不使能。ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(false);//输入名称符合正则表达式规则QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");//第一个字符为字母,第二个字符为1-9的数字,后面接0-2个数字字符ui->lineEdit->setValidator(new QRegExpValidator(regExp,this));//将QRegExpValidator对象设置为this的一个子对象,当this对象删除,该对象自送删除。//设置信号槽连接connect(ui->buttonBox,SIGNAL(accepted()),this,SLOT(accept()));connect(ui->buttonBox,SIGNAL(rejected()),this,SLOT(reject()));}HelloDialog::~HelloDialog()
{delete ui;
}void HelloDialog::on_lineEdit_textChanged()
{ui->buttonBox->button(QDialogButtonBox::Ok)->setEnabled(ui->lineEdit->hasAcceptableInput());//当lineEdit对象输入符合正则表达式,ok键使能。
}

mian.c

#include "hellodialog.h"
#include <QApplication>int main(int argc, char *argv[])
{QApplication a(argc, argv);HelloDialog w;w.show();return a.exec();
}

ui_hellodialog.h

此文件不需要编写,运行时根据ui文件自动生成。

/********************************************************************************
** Form generated from reading UI file 'hellodialog.ui'
**
** Created by: Qt User Interface Compiler version 4.8.7
**
** WARNING! All changes made in this file will be lost when recompiling UI file!
********************************************************************************/#ifndef UI_HELLODIALOG_H
#define UI_HELLODIALOG_H#include <QtCore/QVariant>
#include <QtGui/QAction>
#include <QtGui/QApplication>
#include <QtGui/QButtonGroup>
#include <QtGui/QDialog>
#include <QtGui/QDialogButtonBox>
#include <QtGui/QHBoxLayout>
#include <QtGui/QHeaderView>
#include <QtGui/QLabel>
#include <QtGui/QLineEdit>
#include <QtGui/QVBoxLayout>QT_BEGIN_NAMESPACEclass Ui_HelloDialog
{
public://窗口上使用到的控件声明QVBoxLayout *verticalLayout;QHBoxLayout *horizontalLayout;QLabel *label;QLineEdit *lineEdit;QDialogButtonBox *buttonBox;//将对话框对象传入到该函数中,进行布局void setupUi(QDialog *HelloDialog){if (HelloDialog->objectName().isEmpty())HelloDialog->setObjectName(QString::fromUtf8("HelloDialog"));//设定对话框默认名称HelloDialog->resize(210, 69);//竖直布局设定verticalLayout = new QVBoxLayout(HelloDialog);verticalLayout->setSpacing(6);verticalLayout->setContentsMargins(11, 11, 11, 11);verticalLayout->setObjectName(QString::fromUtf8("verticalLayout"));//水平布局设定horizontalLayout = new QHBoxLayout();horizontalLayout->setSpacing(6);horizontalLayout->setObjectName(QString::fromUtf8("horizontalLayout"));//标签设定label = new QLabel(HelloDialog);label->setObjectName(QString::fromUtf8("label"));horizontalLayout->addWidget(label);//行编辑器设定lineEdit = new QLineEdit(HelloDialog);lineEdit->setObjectName(QString::fromUtf8("lineEdit"));horizontalLayout->addWidget(lineEdit);verticalLayout->addLayout(horizontalLayout);//按键盒子设定buttonBox = new QDialogButtonBox(HelloDialog);buttonBox->setObjectName(QString::fromUtf8("buttonBox"));buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);verticalLayout->addWidget(buttonBox);#ifndef QT_NO_SHORTCUTlabel->setBuddy(lineEdit);
#endif // QT_NO_SHORTCUTretranslateUi(HelloDialog);//设定空间显示文字QMetaObject::connectSlotsByName(HelloDialog);//根据定义名称,自动调用槽函数} // setupUivoid retranslateUi(QDialog *HelloDialog){HelloDialog->setWindowTitle(QApplication::translate("HelloDialog", "\344\275\240\345\245\275\357\274\201", 0, QApplication::UnicodeUTF8));label->setText(QApplication::translate("HelloDialog", "\345\220\215\347\247\260(&N)\357\274\232", 0, QApplication::UnicodeUTF8));} // retranslateUi};namespace Ui {class HelloDialog: public Ui_HelloDialog {};//定义一个空子类Ui::HelloDialog
} // namespace UiQT_END_NAMESPACE
#endif // UI_HELLODIALOG_H
http://www.jmfq.cn/news/5001139.html

相关文章:

  • 如何做后台管理员网站/温州seo招聘
  • 注册免费网站/免费做网站怎么做网站链接
  • 电子商务网站建设的步骤过程/seo运营推广
  • 网站 首页 栏目 内容/seo快速排名首页
  • 做地方网站赚钱吗/seo外包 杭州
  • 建设项目环保备案网站/关于进一步优化当前疫情防控措施
  • 中国交通建设监理协会官方网站/百度网站推广
  • 手机软件做的相册怎样传到网站/郑州seo培训
  • 网站服务器系统盘满了怎么清理/长沙搜索排名优化公司
  • 网站怎样优化seo/深圳网站优化推广
  • 大型公司为什么做网站/竞价排名采用什么计费方式
  • 昆明云纺片区网站建设/怎么优化网站关键词的方法
  • 网站图片分辨率尺寸/蚁坊软件舆情监测系统
  • 炫酷的个人网站/免费的网络推广平台
  • 那些网站可以做问答/中国大数据平台官网
  • 广州荔湾区网站建设/1688网站
  • 网站栏目怎么做301定向/优化公司
  • 外国企业网站模板免费下载/百度联盟怎么加入
  • 建设项目环保竣工验收备案网站/seo免费教程
  • 搜索引擎搜不到网站/长沙哪家网络公司做网站好
  • vs做的网站排版错位/百度查重免费
  • 日本图形设计网站/网站建站教程
  • 深圳营销型网站公司电话/媒体网站
  • 网站建设的数据所有权/广告招商
  • 泗洪做网站/东莞seo优化方案
  • 电子商务网站模板/百度seo关键词优化方案
  • wordpress页面diy/谷歌seo优化推广
  • 广告营销策略有哪些/网站内容优化怎么去优化呢
  • 金华网站建设平台/外贸营销网站制作
  • 网站公安备案一般什么可以做/seo外包是什么