Matching Style of Existing Buttons

Hello!
I’m working on a plugin where I add a new button to the toolbar at the top of the screen and I’m having a lot of trouble getting the button’s appearance to match the rest of the bar. Ideally I’d like to just take all of the styling from the wrap-around-mode button and transfer it to mine, but I haven’t been able to find a good way to do that. I’ve gotten most of the way there with this code, but the colors and outline still don’t match:

        self.tool_button.setText("New layer alpha inheritance")
        self.tool_button.setToolTip("New layer alpha inheritance")
        self.tool_button.setBaseSize(wraparound_button.baseSize())
        self.tool_button.setAutoFillBackground(wraparound_button.autoFillBackground())
        self.tool_button.setBackgroundRole(wraparound_button.backgroundRole())
        self.tool_button.setForegroundRole(wraparound_button.foregroundRole())
        self.tool_button.setContentsMargins(wraparound_button.contentsMargins())
        self.tool_button.setContextMenuPolicy(wraparound_button.contextMenuPolicy())
        self.tool_button.setGeometry(wraparound_button.geometry())
        self.tool_button.setMaximumSize(wraparound_button.maximumSize())
        self.tool_button.setMinimumSize(wraparound_button.minimumSize())
        self.tool_button.setStyle(wraparound_button.style())
        self.tool_button.setSizePolicy(wraparound_button.sizePolicy())
        self.tool_button.setToolButtonStyle(wraparound_button.toolButtonStyle())
        self.tool_button.setPalette(wraparound_button.palette())
        self.tool_button.setGraphicsEffect(wraparound_button.graphicsEffect())

(also setting each of these fields manually feels hecka jank haha)

Here’s a picture of the button as it currently exists:

Probably this buttons are of specific QT type. Maybe Python Plugin Developer Tools can help? It allows to introspect ui elements, query classes, check all flags on QT object, etc.

1 Like

The other tool buttons have autoRaise enabled, that’s why they appear flat when the mouse is not hovering.

And with the color, they cheat a bit, QToolButton does not offer a separate highlight color when a button is toggled on, so the color palette gets modified on every toggle for that.

3 Likes

Oh nice! I never in a million billion years would have guessed that the palette would get swapped on every toggle so I’m glad I asked. I ended up getting it to work by toggling the mirror button on/off and storing the palettes it used, then applying them to my button when it toggled

WOOHOO
button_image

4 Likes

This topic was automatically closed 4 days after the last reply. New replies are no longer allowed.