[Interest] Struggling with moveEvent()

Adam Light aclight at gmail.com
Thu Oct 4 16:56:52 CEST 2018

On Wed, Oct 3, 2018 at 6:27 AM Murphy, Sean <smurphy at walbro.com> wrote:

> This looks promising - I had never stumbled across QWidgetAction before.
> Although now
> that you point it out, I've discovered the section of the QMenu
> documentation that I
> previously skimmed over that mentions it!
> Is the code in your paintEvent() something you can share, if there's
> anything noteworthy
> happening in there?

I don't think it's very noteworthy, but here's what we're using:

void WMColorPickerToolButton::paintEvent(QPaintEvent* event) {


	QStylePainter painter(this);



	// Draw the regular tool button elements.

	QStyleOptionToolButton opt;


	// Clear the text in the opt object since text that we don't

	// draw in this function will get in the way of the button's

	// regular text.


	painter.drawComplexControl(QStyle::CC_ToolButton, opt);

	// Get the rectangle into which the sample should be drawn.

	QRect destField(style()->subControlRect(QStyle::CC_ToolButton, &opt,

	// Offset the rectangle by the style's button margin pixel metric.

	int margin = style()->pixelMetric(QStyle::PM_ButtonMargin,  &opt, this);

	destField.adjust(margin, margin, -margin, -margin);

	// Draw the patterned background

	WMColorPickerWidget::drawPatternedBackground(&painter, destField);

	// Draw the color sample.

	painter.fillRect(destField, _colorPickerAction->currentColor());

	// Draw an outline rectangle.

	QRect outlineRect(destField);

	outlineRect.adjust(0, 0, -1, -1);



	int thickness = 1;

	outlineRect.adjust(thickness, thickness, -thickness, -thickness);



	// Restore the painter.



WMColorPickerWidget::drawPatternedBackground draws a checkerboard
background so that it's more obvious if a color's alpha value is not fully

To be clear, that's the paintEvent for the tool button itself.  The QWidget
that's used by the QWidgetAction is just a container for other widgets in a
layout and doesn't have any need to reimplement paintEvent.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20181004/5db4dca9/attachment.html>

More information about the Interest mailing list