Menu

Is there support for the negation operator using PythonQt::TypeSlots?

Help
2020-11-16
2020-11-18
  • Flower lady

    Flower lady - 2020-11-16

    Hey folks, is there a way to support negation for my custom types, e.g., something = -my_type_instance? I have in-place subtraction implemented using the correct flags and overriding iadd in my C++ wrapper for my class, but it seems like negation is a bit different.

     
  • Florian Link

    Florian Link - 2020-11-16

    I looked this up, you actually need an overloaded __sub__ slot without second object, which returns a negated object. This is due to the code generator and c++, where negation and subtraction is the same -operator

     
  • Flower lady

    Flower lady - 2020-11-17

    Wonderful, thanks Florian! Any tips on where to go to look up these sorts of things? The documentation is a bit sparse. I can also dig into the code, but there is a LOT of code, and it's hard to tell where the meat of the C++ to Python conversion is happening.

     
  • Flower lady

    Flower lady - 2020-11-18

    I ask because I am trying to get a slot working for getitem, but no dice for me, so I might be using the wrong types. I attempted with :

    public slots:
    ...
        double __getitem__(MyVectorType* v, int idx) const;
    
     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.