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_())
  • 相关阅读:
    Django Web开发学习笔记(1)
    SessionFactory 执行原生态的SQL语句
    Java中使用FileputStream导致中文乱码问题的修改方案
    JavaScript中的namespace
    SpringMVC配置文件
    Python 贝叶斯分类
    Struct(二)
    Struct2 (一)
    SpingMVC ModelAndView, Model,Control以及参数传递
    window.onload
  • 原文地址:https://www.cnblogs.com/jkmiao/p/10093417.html
Copyright © 2011-2022 走看看