• 对话框


    本例子涉及到了快捷键,信号,槽,读者自己看代码,我给出了框架。

    find.h文件代码如下:

    #ifndef FIND_H
    #define FIND_H
    
    #include <QtGui>
    #include "ui_find.h"
    
    class Find : public QDialog
    {
    	Q_OBJECT
    
    public:
    	Find(QWidget *parent = 0, Qt::WFlags flags = 0);
    	~Find();
    
    signals:
    	void findNext1(const QString &str,Qt::CaseSensitivity cs);
    	void findPrevious1(const QString &str,Qt::CaseSensitivity cs);
    
    private slots:
    	void findClicked();
    	void enableFindButton(const QString &str);
    
    private:
    	Ui::FindClass ui;
    
    	QLabel *label;
    	QLineEdit *textLine;
    	QCheckBox *matchBox;
    	QCheckBox *searchBox;
    	QPushButton *findButton;
    	QPushButton *quitButton;
    };
    
    #endif // FIND_H
    

     find.cpp代码如下:

    #include "find.h"
    
    Find::Find(QWidget *parent, Qt::WFlags flags)
    	: QDialog(parent, flags)
    {
    	ui.setupUi(this);
    
    	label=new QLabel(tr("Find &What:"));
    	textLine=new QLineEdit();
    	label->setBuddy(textLine);
    	QHBoxLayout *hlayout=new QHBoxLayout();
    	hlayout->addWidget(label);
    	hlayout->addWidget(textLine);
    
    	findButton=new QPushButton(tr("&Find"));
    	findButton->setEnabled(false);
    	findButton->setDefault(true);
    	quitButton=new QPushButton(tr("&Quit"));
    	QVBoxLayout *vlayout=new QVBoxLayout();
    	vlayout->addWidget(findButton);
    	vlayout->addWidget(quitButton);
    
    	matchBox=new QCheckBox(tr("Match &Case"));
    	searchBox=new QCheckBox(tr("Search &Backword"));
    	QVBoxLayout *vlayout1=new QVBoxLayout();
    	vlayout1->addWidget(matchBox);
    	vlayout1->addWidget(searchBox);
    
    	QHBoxLayout *mainLayout=new QHBoxLayout();
    	mainLayout->addLayout(hlayout);
    	mainLayout->addLayout(vlayout);
    	mainLayout->addLayout(vlayout1);
    	setLayout(mainLayout);
    
    	setWindowTitle(tr("Find"));
    	setFixedHeight(sizeHint().height());
    
    	connect(textLine,SIGNAL(textChanged(const QString &)),this,SLOT(enableFindButton(const QString&)));
    	connect(findButton,SIGNAL(clicked()),this,SLOT(findClicked()));
    	connect(quitButton,SIGNAL(clicked()),this,SLOT(close()));
    }
    
    Find::~Find()
    {
    
    }
    
    // void Find::findNext1(const QString &str,Qt::CaseSensitivity cs){
    //     //do something here
    // }
    // 
    // void Find::findPrevious1(const QString &str,Qt::CaseSensitivity){
    //            //do something here
    // }
    
    void Find::findClicked(){
    	QString text=textLine->text();
    	Qt::CaseSensitivity cs=matchBox->isChecked() ? Qt::CaseSensitive:Qt::CaseInsensitive;
    	if(searchBox->isChecked()){
    		emit findPrevious1(text,cs);
    	}else{
    		emit findNext1(text,cs);
    	}
    }
    
    void Find::enableFindButton(const QString &str){
    	findButton->setEnabled(!(str.isEmpty()));
    }
    

     main.cpp

    #include "find.h"
    #include <QtGui/QApplication>
    
    int main(int argc, char *argv[])
    {
    	QApplication a(argc, argv);
    	Find w=new Find();
    	w.show();
    	return a.exec();
    }
    
  • 相关阅读:
    专题1
    HDU-6968(DP,和DP)
    ios环境下H5 input 选择图片在函数回调中失效的问题
    vue自定义组件的坑:数组绑定与引号的使用
    关于布局的胡言乱语
    flex布局小结
    微信小程序中overflow:scroll失效的问题
    微信小程序图片的比例问题
    vue用多了反而疏忽了选择器的使用
    在vue项目中做一个类ctrl+f的搜索功能
  • 原文地址:https://www.cnblogs.com/rollenholt/p/2262233.html
Copyright © 2020-2023  润新知