栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

Qt对话框Dialog之查找对话框2

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Qt对话框Dialog之查找对话框2

一、查找对话框UI

代码如下(示例):

#ifndef GOTOCELL_H
#define GOTOCELL_H
#include 
#include 

class QPushButton;
class QLabel;
class QLineEdit;
class GoToCell : public QDialog
{
    Q_OBJECT

public:

    explicit GoToCell(QWidget *parent = 0);
private slots:
    void slotTextChanged();
private:

    QPushButton * mPtr_ok;
    QPushButton * mPtr_cancel;
    QLabel * mPtr_label;
    QLineEdit * mPtr_lineEdit;
};

#endif // GOTOCELL_H


代码如下(示例):

#include "go_to_cell.h"
#include 
#include 
#include 
#include 
#include 
#include 
GoToCell::GoToCell(QWidget *parent):QDialog(parent)
{
    this->setWindowTitle(tr("Go To Cell"));
    mPtr_ok = new QPushButton(tr("OK"));
    mPtr_cancel = new QPushButton(tr("Cancel"));
    mPtr_label = new QLabel(tr("&Cell Location"));
    //正则
    QRegExp regExp("[A-Za-z][1-9][0-9]{0,2}");
    mPtr_lineEdit = new QLineEdit;
    //lineEdit 添加内置检验器
    mPtr_lineEdit->setValidator(new QRegExpValidator(regExp,this));
    mPtr_label->setBuddy(mPtr_lineEdit);
    QHBoxLayout * top = new QHBoxLayout;
    top->addWidget(mPtr_label);
    top->addWidget(mPtr_lineEdit);

    QHBoxLayout * bottom = new QHBoxLayout;
    bottom->addStretch();
    bottom->addWidget(mPtr_ok);
    bottom->addWidget(mPtr_cancel);

    QVBoxLayout * main = new QVBoxLayout;
    main->addLayout(top);
    main->addLayout(bottom);

    this->setLayout(main);

    connect(mPtr_ok,SIGNAL(clicked()),this,SLOT(accept()));
    connect(mPtr_cancel,SIGNAL(clicked()),this,SLOT(reject()));
    connect(mPtr_lineEdit,SIGNAL(textChanged(QString)),this,SLOT(slotTextChanged()));
}

void GoToCell::slotTextChanged()
{
    mPtr_ok->setEnabled(mPtr_lineEdit->hasAcceptableInput());
}



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/988429.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号