Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using enum elements from C++ Qt Object in python #71

Open
kwisp opened this issue May 31, 2022 · 0 comments
Open

Using enum elements from C++ Qt Object in python #71

kwisp opened this issue May 31, 2022 · 0 comments
Labels
question Further information is requested

Comments

@kwisp
Copy link

kwisp commented May 31, 2022

Short

In Python not found enum elements from C++ class derived from QObject added to PythonQt via addDecorators() and registerClass(QMetaObject*).

Versions

Qt 5.12.8
Python 3.8.10
g++ (Ubuntu 9.4.0-1ubuntu1~20.04.1) 9.4.0
PythonQt master fb16d6e on 3 Nov 2021

Example Code

Add to std example PyDecoratorsExample
ExternalWidget.h

#ifndef EXTERNAL_W_HH_
#define EXTERNAL_W_HH_

#include <QtWidgets/QWidget>

class ExternalWidget : public QWidget
{
  Q_OBJECT

public:
  enum EType
  {
    Aone,
    Atwo,
    Athree,
    Afour
  };

  Q_ENUM(EType)

  ExternalWidget(QWidget* parent = nullptr);
  ~ExternalWidget();

public slots:
  void widgetSlot(){};
};

#endif  // EXTERNAL_W_HH_

ExternalWidget.cpp

#include "ExternalWidget.h"

ExternalWidget::ExternalWidget(QWidget* parent) : QWidget(parent)
{
}

ExternalWidget::~ExternalWidget()
{
}

add to main.cpp

PythonQt::self()->registerClass(&ExternalWidget::staticMetaObject, "QtGui");

add to example.py

w = QtGui.ExternalWidget()
w.move(100,100)
w.show()

add ExternalWidget.h and ExternalWidget.cpp to HEADERS a SOURCES in PyDecoratorsExample.pro
In python console can use
dir(QtGui.ExternalWidget)

There are no enum elements Aone, Atwo e.t.c. and enum EType

Whats wrong???
I try to use Q_ENUMS() and result is the same. :(

@mrbean-bremen mrbean-bremen added the question Further information is requested label Nov 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants