[PyQt] Re: QStyle manipulations

Giovanni Bajo rasky at develer.com
Tue Jul 28 01:19:37 BST 2009


On Tue, 28 Jul 2009 01:24:19 +0200, "Hans-Peter Jansen" <hpj at urpla.net>
wrote:
> Am Montag, 27. Juli 2009 schrieb Phil Thompson:
>> On Mon, 27 Jul 2009 22:56:57 +0200, "Hans-Peter Jansen" <hpj at urpla.net>
>>
>> wrote:
>> > Am Montag, 27. Juli 2009 schrieb Phil Thompson:
>> >> On Mon, 27 Jul 2009 21:03:59 +0200, "Hans-Peter Jansen"
>> >> <hpj at urpla.net>
>> >>
>> >> >>     const_cast<QStyle
>> >> >> *>(this)->qt_metacall(QMetaObject::InvokeMetaMethod,
>> >> >> d->layoutSpacingIndex, param); return result;
>> >> >> }
>> >> >>
>> >> >>
>> >> >> Do you see any chance of getting this to behave?
>> >> >
>> >> > Hmm, from what I can see (though I _am_ blind, when it comes to the
>> >> > guts from sip and PyQt), most of needed mechanics is in place. The
>> >> > question
>> >>
>> >> is,
>> >>
>> >> > what have to be done, that:
>> >> >  * the metaObject is able to locate our method with
>> >> >    metaObject()->indexOfMethod(), and
>> >> >  * qt_metacall is able to invoke our method
>> >> >
>> >> > The former may already do what it should (otherwise parts of the
>> >> > QMetaObject
>> >> > stuff won't do at all, it's even wrapped in qobjectdefs.sip).
>> >> >
>> >> > The latter seems to be the problem, since it may need some kind of
>> >> >
>> >> >
>> >> > Parts of qpy/QtCore/qpycore_pyqtproxy.cpp look like they handle
>>
>> similar
>>
>> >> > cases. Is it possible to register our method at run-time and be
done
>> >> > with
>> >> >
>> >> > it, Phil?
>> >>
>> >> You can certainly work around the problem with C++ code - but I'm not
>> >> sure if SIP will allow you to place the C++ code in the right place.
>> >
>> > Hmm, as it stands, I'm lost in a maze of Qt meta object system wrapped
>> > in
>> >
>> > the guts of sip and PyQt. It looks like it takes some kind of manual
>> > registration in the Q*Style constructor on C++ level, which is
normally
>> > covered in the Q_OBJECT macro, but I've no idea, how it all fits
>> > together
>> >
>> > conceptually, thus unable to come up with some kind of solution to the
>> > problem. Will try to solve the problem differently, uglier, much
>> > uglier. Rarely I regret to be a Python guy, like today :-(.
>>
>> You may get away with a Python implementation by sub-classing the QStyle
>> you want to modify and using the pyqtSlot decorator on the method you
>> want Qt to call.
> 
> Tried that already, without success. Qt dispatches the call to 
> layoutSpacingImplementation() in QStyle.layoutSpacing(). I also tried to 
> intercept that, but since it is not virtual, that does not work, either.
> (That's the whole reason for these metaObject games, Qt playes here).
> 
> I already intercepted a couple of other methods, but none allows reducing

> the spacing. There's another QStyle method, which may fit: 
> combinedLayoutSpacing, but that cannot be intercepted either (because, it

> is not virtual).
> 
> The basic problem I try to solve, is that I've created a typical QWidget 
> based sub class of a combined QCheckBox and QToolButton. And while on my 
> Linux desktop with QPlastiqueStyle the spacing is well (similar to other 
> widgets, on the Mac with QMacStyle the vertical spacing of those custom 
> widgets is nearly twice as high as ordinary check boxes. I've tried to 
> control the margins from within my widget, but the margins are controlled

> via private QWidget methods and attributes - unreachable from PyQt.

Isn't it possible to adjust the margins through CSS?
-- 
Giovanni Bajo
Develer S.r.l.
http://www.develer.com


More information about the PyQt mailing list