[Qt-interest] QRect::contains is lying to me
Paul England
pengland at cmt-asia.com
Mon Dec 21 06:32:38 CET 2009
Hello:
This is a little irksome. I'm basically storing geometries of QWidgets
in a std::map. When a widget moves, before dropping it I make sure it's
not going to be on top of another QWidget. Sounds easy enough, right?
I'm checking to make sure the geometries of the QObjects don't collide
with QRect::contains(). It keeps telling me they don't when they
clearly do. Am I missing something? Here's the code:
std::map<QWidget*, QRect> geometries;
int drag_dialog::geometry_okay( QWidget* self, const QRect& rect ) const
{
map<QWidget*, QRect>::const_iterator it;
for ( it = geometries.begin(); it != geometries.end(); it++ ) {
if ( (*it).first == self ) {
continue;
}
if ( rect.contains( (*it).second ) ) {
printf( "Bubuuu... no dice\n" );
return 0;
} else {
printf( "%d,%d -> %d,%d does not conflict with %d,%d ->
%d,%d\n",
rect.topLeft().x(), rect.topLeft().y(),
rect.bottomRight().x(), rect.bottomRight().y(),
(*it).second.topLeft().x(), (*it).second.topLeft().y(),
(*it).second.bottomRight().x(), (*it).second.bottomRight().y() );
}
}
return 1;
}
Output I got when I clearly dropped one widget on another:
9,8 -> 109,254 does not conflict with 0,0 -> 99,245
Thanks.
More information about the Qt-interest-old
mailing list