zoukankan      html  css  js  c++  java
  • ubuntu16.04 install qtcreator

    1. 安装相关软件,搭建环境

    sudo apt install qt-creator
    sudo apt install qt5-default
    
    source python35/bin/activate pip
    install pyqt5

     2. 输入qtcreator,打开设计界面,进行相关控件拖放和属性配置即可。

    简单的加减小例子

    #include "mainwindow.h"
    #include "ui_mainwindow.h"
    
    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
    }
    
    MainWindow::~MainWindow()
    {
        delete ui;
    }
    
    
    void MainWindow::on_add_clicked(){
    
     int res = ui->M->text().toInt()+ ui->N->text().toInt();
     ui->result->setText(QString::number(res));
    }
    
    void MainWindow::on_sub_clicked()
    {
    
        int res = ui->M->text().toInt() - ui->N->text().toInt();
        ui->result->setText(QString::number(res));
    
    }

    3.  利用pyqt5,使用python进行编程

    把form.ui文件编译为form.py文件,执行如下命令

    pyuic5 form.ui -o form.py

    4. 打开这个form.py这个文件,可以看到生成了Ui_Form这个类,有一些我们添加的控件。我们只需要导入类,做初始化,然后编写自定义的槽函数就可以了。

    from PyQt5 import QtWidgets, QtGui
    import sys
    
    from form import Ui_Form    # 导入生成form.py里生成的类
    
    class mywindow(QtWidgets.QWidget,Ui_Form):    
        def __init__(self):    
            super(mywindow,self).__init__()    
            self.setupUi(self)
    
        #定义槽函数
        def hello(self):
            self.textEdit.setText("hello world")
    
    app = QtWidgets.QApplication(sys.argv)
    window = mywindow()
    window.show()
    sys.exit(app.exec_())
  • 相关阅读:
    HDU 2100 LoveKey
    HDU 2111 Saving HDU
    HDU 2132 An easy problem
    PAT 甲级 1081 Rational Sum (数据不严谨 点名批评)
    LWIP内存管理
    LWIP带UCOS操作系统移植
    LWIP协议栈2-
    LWIP协议栈1
    掌握所有IO口的外部中断
    熟悉相关电路,控制I/O口,且配置相关参数,LED,光敏,74LS164数码管
  • 原文地址:https://www.cnblogs.com/jkmiao/p/10093417.html
Copyright © 2011-2022 走看看