Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved How to correctly use QProxyStyles?

    General and Desktop
    2
    3
    1656
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      Justin Sayne last edited by

      I'm trying to hack around the issue that Qt doesn't have native support for text <-> icon spacing on QPushButtons and I can't get my approach using a QProxyStyle to work. I made a class inheriting QProxyStyle which draws a QPushButtonLabel with custom instead of hardcoded spacing and then just try to call setStyle with my custom style on a QPushButton. It doesn't work however, my custom style's drawControl is never called.
      It seems like there is a style hierarchy issue because my button is part of a UI file which inherits the default OS style already. Once QCommonStyle::drawControl calls proxy(), it returns the default QWindowsStyle with my custom style as base style and I think it should be the other way around. This way, QWindowsStyle still does all the drawing and my custom style is never reached.
      I know I can set a base style on my proxy style but since it takes ownership of the base style passed, I don't think I can specifiy the default windows style as base because it will be deleted when my proxy style goes out of scope. Any ideas?

      raven-worx 1 Reply Last reply Reply Quote 0
      • raven-worx
        raven-worx Moderators @Justin Sayne last edited by raven-worx

        @Justin-Sayne said in How to correctly use QProxyStyles?:

        I know I can set a base style on my proxy style but since it takes ownership of the base style passed, I don't think I can specifiy the default windows style as base because it will be deleted when my proxy style goes out of scope.

        why should it go out of scope?

        widget->setStyle( new MyProxyStyle(widget->style()) );
        

        But anyway, simply setting the proxy style wihtout a base-style should do what you want already.
        Show your code please.

        Also note that a QProxyStyle wont work properly when used in conjunction with a QStylesheetStyle (anywhere in the parent-chain!)

        --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
        If you have a question please use the forum so others can benefit from the solution in the future

        J 1 Reply Last reply Reply Quote 2
        • J
          Justin Sayne @raven-worx last edited by

          @raven-worx said in How to correctly use QProxyStyles?:

          why should it go out of scope?

          widget->setStyle( new MyProxyStyle(widget->style()) );
          

          The QWidget doc says, setStyle doesn't take ownership of the QStyle pointer passed, so it seemed like passing it this way produces memory leaks. That's also why I had it coupled to the lifetime of my dialog I was showing the button in.

          Also note that a QProxyStyle wont work properly when used in conjunction with a QStylesheetStyle (anywhere in the parent-chain!)

          I can show the code if you still want, but I'm pretty sure, that's the problem. The button is part of a UI file where I'm making heavy use of style sheets. Is there any other way to get customizeable icon/text spacing for QPushButton and ideally QToolButton as well? I can't believe Qt doesn't support this natively...

          1 Reply Last reply Reply Quote 0
          • First post
            Last post