Qt学习第三天

头文件:


#ifndef GOTOCELLDIALOG_H
#define GOTOCELLDIALOG_H
 
#include<QDialog>
 
class QLabel;
class QLineEdit;
class QPushButton;
 
class GOTOCELLDIALOG:public QDialog
{
    Q_OBJECT
public:
    GOTOCELLDIALOG(QWidget *parent=0);
 
signals:
    void stop();
 
private slots:
    void enableokButton(const QString &text);
 
private:
    QLabel *label;
    QLineEdit *lineEdit;
    QPushButton *okButton;
    QPushButton *cancelButton;
 
};
 
#endif // GOTOCELLDIALOG_H
 
 

实现文件:

#include<QtGui>
#include "gotocelldialog.h"
 
GOTOCELLDIALOG::GOTOCELLDIALOG(QWidget *parent)
    :QDialog(parent)
{
    label=new QLabel(tr("&Cell Location:"));
    lineEdit=new QLineEdit;
    label->setBuddy(lineEdit);
 
    okButton=new QPushButton(tr("&OK"));
    cancelButton=new QPushButton(tr("&Cancel"));
    okButton->setDefault(true);
    okButton->setEnabled(false);
 
 
    connect(lineEdit,SIGNAL(textChanged(const QString &)),this,SLOT(enableokButton(const QString &)));
 
    connect(okButton,SIGNAL(clicked()),this,SLOT(close()));
 
    connect(cancelButton,SIGNAL(clicked()),lineEdit,SLOT(clear()));
 
    QHBoxLayout *topLayout=new QHBoxLayout;
    topLayout->addWidget(label);
    topLayout->addWidget(lineEdit);
 
    QHBoxLayout *bottomLayout=new QHBoxLayout;
    bottomLayout->addWidget(okButton);
    bottomLayout->addWidget(cancelButton);
 
    QVBoxLayout *mainlayout=new QVBoxLayout;
    mainlayout->addLayout(topLayout);
    mainlayout->addLayout(bottomLayout);
    setLayout(mainlayout);
 
    setWindowTitle(tr("Go To Cell"));
    setFixedHeight(sizeHint().height());
 
}
 
void GOTOCELLDIALOG::enableokButton(const QString &text)
{
    okButton->setEnabled(!lineEdit->text().isEmpty());
}
 
 
 
 

主函数:

#include <QtGui/QApplication>
#include "gotocelldialog.h"
 
int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
 
    GOTOCELLDIALOG *dialog=new GOTOCELLDIALOG;
    dialog->show();
 
    return a.exec();
}
 



感想:通过今天的实践,我才深刻的体会到了什么叫做“能看得懂代码,却不会写代码”。看懂和会写之间还有很大的距离。尽管今天所实现的功能非常简单,而且也没有一次编译通过,但我觉得进步还是有的。对什么时候该用this指针有了进一步理解。同时我个人认为,手写代码更能锻炼一个人的能力,虽然来的更慢,而且效果不一定很好,但只要长期坚持,所能取得的进步就非常可观。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值