zoukankan      html  css  js  c++  java
  • Qt编写计算器(界面)

    看了几个视频,写了个计算器的界面

    #include <QApplication>
    #include <QWidget>
    #include <QLineEdit>
    #include <QPushButton>
    
    int main(int argc, char *argv[])
    {
        QApplication a(argc, argv);
        QWidget* w = new QWidget(NULL,Qt::WindowCloseButtonHint);//没有最大最小化按钮
        QLineEdit* Le = new QLineEdit(w);
        QPushButton* Button[20] = {0};
        const char* BtnText[20]=
        {
            "7","8","9","+","(",
            "4","5","6","-",")",
            "1","2","3","*","<-",
            "0",".","=","/","C"
        };
        Le->move(10,10);
        Le->resize(240,30);
        Le->setReadOnly(true);//文本框只读,不能通过键盘输入
        for(int i = 0;i<4;i++)
        {
            for(int j = 0;j<5;j++)
            {
                Button[i*5+j] = new QPushButton(w);
                Button[i*5+j]->resize(40,40);
                Button[i*5+j]->move(10 + (10 + 40)*j,(10+40) + (10 + 40)*i);
                Button[i*5+j]->setText(BtnText[i*5+j]);
            }
        }
        w->setWindowTitle("计算器");
    
        w->show();
        w->setFixedSize(w->width(),w->height());//锁定窗口大小
        /*
         *  w->show();
         *   w->setFixedSize(w->width(),w->height());//锁定窗口大小
         * 这两句顺序不能反
         */
    
        return a.exec();
    }

    运行界面如下

  • 相关阅读:
    有向无环图单源最短路径问题
    linux下程序编译出错解决方法
    Ceres入门笔记
    Java 中的数据结构类 Vector 和 ArrayList
    102. Binary Tree Level Order Traversal
    104. Maximum Depth of Binary Tree
    101. Symmetric Tree
    100. Same Tree
    490. The Maze
    骑士游历问题
  • 原文地址:https://www.cnblogs.com/tianxxl/p/10294901.html
Copyright © 2011-2022 走看看