[Interest] setting a widget style for a particular widget class only?

Andy asmaloney at gmail.com
Sun Sep 11 20:06:15 CEST 2016


Thanks Lorenz.

My comment was actually about the call to QStyleFactory::create().  I
wasn't sure if QStyleFactory created it and kept track of it somewhere
(only load a style once?) or if I needed to manage it myself.  Usually when
I write these kinds of methods (static methods on classes which create
things) I like to document who owns the resulting pointer so there's no
question who's going to manage the memory.

---
Andy Maloney  //  https://asmaloney.com
twitter ~ @asmaloney <https://twitter.com/asmaloney>


On Sun, Sep 11, 2016 at 1:35 PM, Lorenz Haas <lykurg at gmail.com> wrote:

> Just for the record - http://doc.qt.io/qt-5/qwidget.html#setStyle: The
> ownership of the style object is not transferred.
>
> 2016-09-10 17:25 GMT+02:00 Andy <asmaloney at gmail.com>:
> > The docs do not specify who owns the pointer, but it looks like the
> object
> > doesn't have a parent so I would assume the caller does.
> >
> > That code was not actual code from my application but, yes, I would
> > recommend only creating and storing the style once and releasing it
> > appropriately.
> >
> > ---
> > Andy Maloney  //  https://asmaloney.com
> > twitter ~ @asmaloney
> >
> >
> > On Sat, Sep 10, 2016 at 11:07 AM, René J.V. Bertin <rjvbertin at gmail.com>
> > wrote:
> >>
> >> On Saturday September 10 2016 09:11:02 Andy wrote:
> >>
> >> Hi Andy,
> >>
> >> Thanks! I'm a bit confused that I didn't think of trying this myself,
> but
> >> it works:
> >>
> >> https://bugsfiles.kde.org/attachment.cgi?id=101015
> >>
> >> Shouldn't one release *style in the dtor?
> >>
> >> R.
> >>
> >>
> >> > René:
> >> >
> >> > I think you can just use QWidget::setStyle().  Haven't tried it for
> >> > QTabBar, but I use it on QButtons.
> >> >
> >> > QStyle   *style = QStyleFactory::create( "fusion" );
> >> > QPushButton   *button = new QPushButton( "foo", this );
> >> > button->setStyle( style );
> >>
> >
> >
> > _______________________________________________
> > Interest mailing list
> > Interest at qt-project.org
> > http://lists.qt-project.org/mailman/listinfo/interest
> >
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20160911/175dc5ef/attachment.html>


More information about the Interest mailing list