Skip to content

Commit

Permalink
🧪 test(PyQt6): add support PyQt6
Browse files Browse the repository at this point in the history
  • Loading branch information
892768447 committed Apr 28, 2024
1 parent 2311dfe commit 7e32bff
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 12 deletions.
9 changes: 7 additions & 2 deletions Test/WigglyWidget/LibWigglyWidget/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,19 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
# 配置安装目录
set(CMAKE_INSTALL_DIR "${CMAKE_SOURCE_DIR}/dist")

# 静态库
set(BUILD_SHARED_LIBS OFF)

find_package(QT NAMES Qt6 Qt5 REQUIRED COMPONENTS Widgets)
find_package(Qt${QT_VERSION_MAJOR} REQUIRED COMPONENTS Widgets)

add_library(LibWigglyWidget STATIC wigglywidget.cpp wigglywidget.h)
add_library(LibWigglyWidget wigglywidget.cpp wigglywidget.h)

target_link_libraries(LibWigglyWidget PRIVATE Qt${QT_VERSION_MAJOR}::Widgets)

target_compile_definitions(LibWigglyWidget PRIVATE LIBWIGGLYWIDGET_LIBRARY)
if(BUILD_SHARED_LIBS)
target_compile_definitions(LibWigglyWidget PRIVATE LIBWIGGLYWIDGET_LIBRARY)
endif()

# 配置生成的文件安装目录
install(
Expand Down
16 changes: 6 additions & 10 deletions Test/WigglyWidget/LibWigglyWidget/wigglywidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,27 @@
#if defined(WIGGLYWIDGET_LIBRARY)
#define WIGGLYWIDGET_EXPORT Q_DECL_EXPORT
#else
#define WIGGLYWIDGET_EXPORT Q_DECL_IMPORT
#define WIGGLYWIDGET_EXPORT
#endif
#endif

#ifdef Q_OS_WIN
class WIGGLYWIDGET_EXPORT WigglyWidget : public QWidget {
#else
class WigglyWidget : public QWidget {
#endif
Q_OBJECT

public:
public:
WigglyWidget(QWidget *parent = nullptr);

public slots:
public slots:
void setText(const QString &newText);

protected:
protected:
virtual void paintEvent(QPaintEvent *event) override;
virtual void timerEvent(QTimerEvent *event) override;

private:
private:
QBasicTimer timer;
QString text;
int step;
};

#endif // WIGGLYWIDGET_H
#endif // WIGGLYWIDGET_H
3 changes: 3 additions & 0 deletions Test/WigglyWidget/PyQtWrapper/TestWigglyWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,7 @@ def __init__(self, *args, **kwargs):
app = QApplication(sys.argv)
w = TestWigglyWidget()
w.show()
w.resize(800, 600)
if not hasattr(app, "exec_"):
app.exec_ = app.exec
sys.exit(app.exec_())
1 change: 1 addition & 0 deletions Test/WigglyWidget/PyQtWrapper/pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ sip-include-dirs = [
"/Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/PyQt5/bindings",
"/usr/local/lib64/python3.6/site-packages/PyQt5/bindings",
"C:/soft/Python311/Lib/site-packages/PyQt5/bindings",
"C:/soft/Python/lib/site-packages/PyQt6/bindings"
]

# Configure the building of the fib bindings.
Expand Down
2 changes: 2 additions & 0 deletions Test/WigglyWidget/PyQtWrapper/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
PyQt5
PyQt6
sip
PyQt5-sip
PyQt6-sip
PyQt-builder

0 comments on commit 7e32bff

Please sign in to comment.