Qt Designer Custom Widget: using flags

Denis Rouzaud

I have a problem with the declaration of flags in a widget which is used as a custom widget for QtDesigner.

This widget is a QComboBox using a filter proxy model, called QgsMapLayerComboBox

In the filter proxy model (QgsMapLayerProxyModel), I have defined flags:

class GUI_EXPORT QgsMapLayerProxyModel : public QSortFilterProxyModel
{
    Q_OBJECT
    Q_FLAGS( Filters )
  public:
    enum Filter
    {
      NoFilter = 1,
      RasterLayer = 2,
      NoGeometry = 4,
      PointLayer = 8,
      LineLayer = 16,
      PolygonLayer = 32,
      HasGeometry = PointLayer | LineLayer | PolygonLayer,
      VectorLayer = NoGeometry | HasGeometry
    };
    Q_DECLARE_FLAGS( Filters, Filter )

    ...
};

Q_DECLARE_OPERATORS_FOR_FLAGS( QgsMapLayerProxyModel::Filters )

Now I want to be able to define these settings directly in Qt Designer. Hence, I have reused the flags from the proxy model class in the combo box class:

class GUI_EXPORT QgsMapLayerComboBox : public QComboBox
{
    Q_OBJECT

    Q_FLAGS( QgsMapLayerProxyModel::Filters )
    Q_PROPERTY( QgsMapLayerProxyModel::Filters filters READ filters WRITE setFilters )

  public:
    explicit QgsMapLayerComboBox( QWidget *parent = 0 );

    //! setFilters allows fitering according to layer type and/or geometry type.
    void setFilters( QgsMapLayerProxyModel::Filters filters );

    //! currently used filter on list layers
    QgsMapLayerProxyModel::Filters filters(){ return mProxyModel->filters(); }
}

This is working as expected.

But, these widgets are also compiled in a python library using SIP. I have created a module for pyuic (in /usr/lib/python2.7/dist-packages/PyQt4/uic/widget-plugins) so it knows where to look for the widget:

pluginType = MODULE
def moduleInformation():
    return "qgis.gui", ("QgsMapLayerCombobox", )

Now, the problem is that pyuic complains: AttributeError: unknown enum QgsMapLayerProxyModel::RasterLayer because it can't find QgsMapLayerProxyModel.

The only solution that came to my mind was to duplicate the flags in QgsMapLayerComboBox:

class GUI_EXPORT QgsMapLayerComboBox : public QComboBox
{
    Q_OBJECT

    Q_FLAGS( Filters2 )
    Q_PROPERTY( Filters2 filters2 READ filters2 WRITE setFilters2 )

  public:
    typedef QgsMapLayerProxyModel::Filter Filter2;
    typedef QgsMapLayerProxyModel::Filters Filters2;

    explicit QgsMapLayerComboBox( QWidget *parent = 0 );

    //! setFilters allows fitering according to layer type and/or geometry type.
    void setFilters2( Filters2 filters );

    //! currently used filter on list layers
    Filters2 filters2(){ return static_cast<Filters2>( mProxyModel->filters() ); }
}

But this is not working: I don't see the settings in Qt Designer: do you know why?

Would you think of a better way to solve this?

PS: this is made within QGIS code.

Matthias Kuhn

Just modify your code, so Qt Designer will know where to find the definition for the required enum:

pluginType = MODULE
def moduleInformation():
     return "qgis.gui", ("QgsMapLayerCombobox", "QgsMapLayerProxyModel" )

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Qt Designer Custom Widget: using flags

From Dev

QT QIcon properties for custom widget in designer

From Dev

QList as a property in qt designer custom widget

From Dev

QT QIcon properties for custom widget in designer

From Dev

QT 5 add a custom widget inherited from QGraphicsView to designer

From Dev

Using PySide custom widgets in Qt Designer

From Dev

Center a widget in a layout with Qt Designer

From Dev

Qt Designer (creator) widget box like widget

From Dev

Using QDialog in QT Designer

From Dev

Using UI design files and having a custom widget with custom constructor QT

From Dev

Custom menu actions in Qt Designer

From Dev

Custom menu actions in Qt Designer

From Dev

How to restore the Qt Creator Designer widget box?

From Dev

How to build Qt with custom compiler and custom flags?

From Dev

Dynamically adding pages to QStackedWidget using a custom widget designed in Qt Creator

From Dev

Qt Designer custom checkbox relative path

From Dev

Accessing Custom Widget In Python Qt?

From Dev

Promote custom widget with custom constructor in QT Creator

From Dev

A way to connect checkbox state to widget visibility in Qt Designer

From Dev

pyqt - position child widget from qt designer near parent

From Dev

PyQt / Qt Designer - Extra parameters for promoted widget without a plugin

From Dev

Inserting an image in GUI using QT Designer

From Dev

Join another window in Qt Designer, using Python

From Dev

Qt designer: How to add widget to a layout in the designer when the layout appears infinitely thin?

From Java

How to connect Qt signals and slots using QT Designer and Visual Studio

From Dev

Using simple python script in qt (via QT-designer)

From Dev

Qt custom widget not showing child widgets

From Dev

How to promote a custom widget in QT Creator

From Dev

Qt set a custom widget inside a QTableView

Related Related

  1. 1

    Qt Designer Custom Widget: using flags

  2. 2

    QT QIcon properties for custom widget in designer

  3. 3

    QList as a property in qt designer custom widget

  4. 4

    QT QIcon properties for custom widget in designer

  5. 5

    QT 5 add a custom widget inherited from QGraphicsView to designer

  6. 6

    Using PySide custom widgets in Qt Designer

  7. 7

    Center a widget in a layout with Qt Designer

  8. 8

    Qt Designer (creator) widget box like widget

  9. 9

    Using QDialog in QT Designer

  10. 10

    Using UI design files and having a custom widget with custom constructor QT

  11. 11

    Custom menu actions in Qt Designer

  12. 12

    Custom menu actions in Qt Designer

  13. 13

    How to restore the Qt Creator Designer widget box?

  14. 14

    How to build Qt with custom compiler and custom flags?

  15. 15

    Dynamically adding pages to QStackedWidget using a custom widget designed in Qt Creator

  16. 16

    Qt Designer custom checkbox relative path

  17. 17

    Accessing Custom Widget In Python Qt?

  18. 18

    Promote custom widget with custom constructor in QT Creator

  19. 19

    A way to connect checkbox state to widget visibility in Qt Designer

  20. 20

    pyqt - position child widget from qt designer near parent

  21. 21

    PyQt / Qt Designer - Extra parameters for promoted widget without a plugin

  22. 22

    Inserting an image in GUI using QT Designer

  23. 23

    Join another window in Qt Designer, using Python

  24. 24

    Qt designer: How to add widget to a layout in the designer when the layout appears infinitely thin?

  25. 25

    How to connect Qt signals and slots using QT Designer and Visual Studio

  26. 26

    Using simple python script in qt (via QT-designer)

  27. 27

    Qt custom widget not showing child widgets

  28. 28

    How to promote a custom widget in QT Creator

  29. 29

    Qt set a custom widget inside a QTableView

HotTag

Archive