PDA

View Full Version : Negative border offset CSS in windows generates error



droneone
8th December 2012, 17:56
Hi all, I'm having an issue with a discrepancy between Windows and OSX in stylesheet (QSS) handling.

Namely, for QSlider-derived widgets, using the 'border-image' property requires me to have a negative border offset for the image to ensure that my custom handle is positioned correctly relative to the border image. Without negative border offsets, the handle is drawn inside the groove (both groove and handle have same heights, but groove has greater width than the range of the handle), and does not look as I intend it to. With a negative border offset, the handle is drawn relative to the groove as intended, but generates the following errors on windows (with crash on some widgets) :



QPainter::drawPixmapFragments - the source rect is not contained by the pixmap's rectangle
ASSERT: "v1 >= 0 && v1 < max" in file painting\qdrawhelper.cpp, line 734
Invalid parameter passed to C runtime function.


It does not generate an errors on OSX, and works as expected there.

Here is the offending QSS:



SlideToggle::groove:horizontal {
border-image: url(:/core/toggle-bg.png);
/* border-left: -9px transparent;
border-right: -8px transparent;
border-bottom: -5px transparent;
border-top: 0px transparent;*/
border: 0px transparent;
padding: 0px;
margin: 0px;
}

SlideToggle::handle:horizontal {
margin:0px;
padding:0px;
image: url(:/core/slider-handle-dark.png);
}

SlideToggle {
margin:4px;
}


Un-commenting the commented code generates a crash 100% of the time on Windows 7, using Qt 4.8.0.

I intend to re-design this element that causes the crash to use something other than a slider (like a QButton, since it only has two states), which is no big deal, but I have other sliders that have required negative offsets (for example, drop-shadows below or above groove) that generate thousands of warnings at run-time using them. Is there any ability to change the relationship between the groove border image and the handle that won't generate these problems on Windows?

Thanks in advance!

droneone
4th January 2013, 20:42
... just a follow-up:

Negative border offsets cause crashes in Windows, and appear to be a bad idea in general, even if they are quite effective in placing on OSX (and I've seen a few references to using them with sliders here on the forum). But, it looks that in Windows the same effect can be created by specifying a negative margin for the handle as long as height and width are specified, e.g.:



SlideToggle::groove:horizontal {
border-image: url(img/toggle-bg.png);
padding: 0px;
margin: 0px;
height: 35px;
width: 75px;

}

SlideToggle::handle:horizontal {
margin:-2px -4px -4px -4px;
padding:0px;
height: 42px;
width:42px;
image: url(img/slider-handle-dark.png);
}