{"id":331,"date":"2021-06-21T09:08:06","date_gmt":"2021-06-21T09:08:06","guid":{"rendered":"http:\/\/gongyikun.cn\/?p=331"},"modified":"2021-06-21T09:08:06","modified_gmt":"2021-06-21T09:08:06","slug":"qt%e7%89%88%e7%94%a8qlcdnumber%e6%98%be%e7%a4%ba%e6%97%b6%e9%97%b4","status":"publish","type":"post","link":"https:\/\/blog.gongyikun.cn\/?p=331","title":{"rendered":"QT\u7248\u7528QLCDnumber\u663e\u793a\u65f6\u95f4"},"content":{"rendered":"<h1>\/\/\u9996\u5148\u662fdialog.h<\/h1>\n<pre><code class=\"language-cpp line-numbers\">#ifndef DIALOG_H\n#define DIALOG_H\n#include &lt;QDialog&gt;\n#include &lt;QLCDNumber&gt;\n#include &lt;QTime&gt;\n#include &lt;QTimer&gt;\n#include &lt;QPalette&gt;\n#include &lt;QVBoxLayout&gt;\n#include &lt;QHBoxLayout&gt;\nnamespace Ui {\nclass Dialog;\n}\nclass Dialog : public QDialog\n{\n    Q_OBJECT\npublic:\n    explicit Dialog(QWidget *parent = 0);\n    ~Dialog();\npublic slots:\n    void showTime();\nprivate:\n    Ui::Dialog *ui;\n    QLCDNumber *time;\n    QTime tim;\n    QTimer *timer;\n};\n#endif \/\/ DIALOG_H\n<\/code><\/pre>\n<h1>\/\/\u63a5\u7740\u662fdialog.cpp<\/h1>\n<pre><code class=\"language-cpp line-numbers\">#include \"dialog.h\"\n#include \"ui_dialog.h\"\nDialog::Dialog(QWidget *parent) :\n    QDialog(parent),\n    ui(new Ui::Dialog)\n{\n    ui-&gt;setupUi(this);\n    resize(200,200);            \/\/\u8bbe\u7f6e\u751f\u6210\u754c\u9762\u7684\u5927\u5c0f\uff0c\u53ef\u4ee5\u62d6\u8fb9\u6846\u6539\u53d8\u754c\u9762\u5927\u5c0f\n    time = new QLCDNumber(this);\n    time-&gt;setDigitCount(8);     \/\/\u8bbe\u7f6elcd\u91cc\u9762\u7684\u4e2a\u6570\uff0c\u683c\u5f0f\u662fhh\uff1amm\uff1ass\uff0c\u603b\u7684\u662f\u516b\u4e2a\u3002\u6240\u4ee5\u8bbe\u7f6e\u4e3a8\n    time-&gt;setFixedSize(80, 60); \/\/\u8bbe\u7f6e\u5927\u5c0f\n    time-&gt;setPalette(Qt::cyan); \/\/\u8bbe\u7f6e\u989c\u8272\n    QVBoxLayout *vbox = new QVBoxLayout;\n    QHBoxLayout *hbox = new QHBoxLayout;\n    vbox-&gt;addWidget(time);\n    hbox-&gt;addLayout(vbox);\n    setLayout(hbox);   \/\/\u8bbe\u7f6e\u5e03\u5c40\uff0c\u5c06lcd\u7a7a\u95f4\u653e\u5230\u4e2d\u95f4\n    timer = new QTimer(this);\n    connect(timer, SIGNAL(timeout()), this, SLOT(showTime()));  \/\/\u7528\u4e00\u4e2a\u5b9a\u65f6\u4fe1\u53f7\u6765\u66f4\u6539\u65f6\u95f4\n    timer-&gt;start(500);  \/\/\u542f\u52a8\u5b9a\u65f6\n}\nDialog::~Dialog()\n{\n    delete ui;\n}\nvoid Dialog::showTime()\n{\n    tim = QTime::currentTime();  \/\/\u83b7\u53d6\u5f53\u5730\u65f6\u95f4\n    QString timestr = tim.toString(\"hh:mm:ss\"); \/\/\u8bbe\u7f6e\u65f6\u95f4\u683c\u5f0f\n    time-&gt;display(timestr);  \/\/\u663e\u793a\u65f6\u95f4\n}\n<\/code><\/pre>\n<h1>\/\/mian.cpp<\/h1>\n<pre><code class=\"language-cpp line-numbers\">#include \"dialog.h\"\n#include &lt;QApplication&gt;\nint main(int argc, char *argv[])\n{\n    QApplication a(argc, argv);\n    Dialog w;\n    w.show();\n    return a.exec();\n}\n<\/code><\/pre>\n<div class=\"clearfix\"><\/div>","protected":false},"excerpt":{"rendered":"<p>\/\/\u9996\u5148\u662fdialog.h #ifndef DIALOG_H #define DIALOG_H #includ [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[21],"tags":[],"_links":{"self":[{"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=\/wp\/v2\/posts\/331"}],"collection":[{"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=331"}],"version-history":[{"count":1,"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=\/wp\/v2\/posts\/331\/revisions"}],"predecessor-version":[{"id":332,"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=\/wp\/v2\/posts\/331\/revisions\/332"}],"wp:attachment":[{"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=331"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=331"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.gongyikun.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=331"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}