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_())
    

    展示一下结果

  • 相关阅读:
    Java: Regular Expressions
    Java: Checked & Unchecked Exceptions
    二叉树的构建和层级打印
    [leetcode] 1032: Stream of Characters: Tries&AC自动机
    [leetcode] 1503: Previous Permutation With One Swap
    robot moving on the surface of a square
    killing rabbits
    Find the longest route with the smallest starting point
    [leetcode] Minimum Number of K Consecutive Bit Flips
    检测设备横屏 || 竖屏的状态
  • 原文地址:https://www.cnblogs.com/superfly123/p/13351621.html
Copyright © 2011-2022 走看看