zoukankan      html  css  js  c++  java
  • 记录一下使用qt designer和pyqt5做界面的过程

    安装PyQt5

    pip install PyQt5 -i https://pypi.douban.com/simple

    安装QTdesigner

    pip install PyQt5-tools -i https://pypi.douban.com/simple

    打开QTdesigner

    我的位于下面的目录
    D:Anaconda3Libsite-packagespyqt5_toolsQtindesigner.exe
    如果报错
    需要将
    D:Anaconda3Libsite-packagesPyQt5Qtpluginsplatforms
    复制到
    D:Anaconda3Libsite-packagespyqt5_toolsQtinplatforms
    就ok了

    Ubuntu特殊情况

    如果报错

    qt.qpa.plugin: Could not load the Qt platform plugin "xcb" in "" even though it was found.
    This application failed to start because no Qt platform plugin could be initialized. Reinstalling the application may fix this problem.
    
    Available platform plugins are: eglfs, linuxfb, minimal, minimalegl, offscreen, vnc, wayland-egl, wayland, wayland-xcomposite-egl, wayland-xcomposite-glx, webgl, xcb.
    
    Aborted (core dumped)
    

    需要终端加入

    export QT_DEBUG_PLUGINS=1
    

    再运行程序进行调试
    查看输出的结果。

    解决方案

    sudo apt install --reinstall libxcb-xinerama0
    

    可能用到的

    sudo ln -sf /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/ /usr/bin/
    
    sudo apt-get install qt5-default qttools5-dev-tools
    
    sudo apt-get install python3-pyqt5
    
    
    sudo apt-get install libx11-dev libxext-dev libxtst-dev
    sudo apt-get install xlibmesa-gl-dev libglu1-mesa-dev
    
    sudo ln -sf /usr/lib/x86_64-linux-gnu/qt5/plugins/platforms/ /usr/bin/
    
    sudo apt-get install libcap2-bin
    

    设计界面

    设计完成后,保存为.ui文件
    在终端中输入命令
    pyuic5 .untitled.ui -o none2.py(pyuic5.bat在conda库中存在)

    修改py文件

    文件上部加入

    from PyQt5 import QtCore, QtGui, QtWidgets
    from PyQt5.QtWidgets import QMainWindow, QWidget, QApplication
    import sys
    

    下部加入

    if __name__ == "__main__":
        app = QApplication(sys.argv)
        mainWindow = QMainWindow()
        ui = Ui_MainWindow()
        ui.setupUi(mainWindow)
        mainWindow.show()
        sys.exit(app.exec_())
    

    展示一下结果

  • 相关阅读:
    HashTable源码浅析(基于jdk1.8.0_231)
    LinkedHashMap源码浅析(基于jdk1.8.0_231)
    SortedSet接口源码浅析(基于jdk1.8.0_231)
    NavigableSet接口源码浅析(基于jdk1.8.0_231)
    TreeSet源码浅析(基于jdk1.8.0_231)
    TreeMap源码浅析(基于jdk1.8.0_231)
    Map接口源码解析(基于jdk1.8.0_231)
    Arrays工具类源码详解(基于jdk1.8.0_231)
    Collections源码详解(基于jdk1.8.0_231)
    BitSet源码详解 (基于jdk1.8.0.231)
  • 原文地址:https://www.cnblogs.com/superfly123/p/13351621.html
Copyright © 2011-2022 走看看