Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to correctly use QProxyStyles?

How to correctly use QProxyStyles?

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 4.0k Views 1 Watching
  • 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 Offline
    J Offline
    Justin Sayne
    wrote on last edited by
    #1

    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-worxR 1 Reply Last reply
    0
    • J Justin Sayne

      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-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by raven-worx
      #2

      @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
      2
      • raven-worxR 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!)

        J Offline
        J Offline
        Justin Sayne
        wrote on last edited by
        #3

        @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
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved