[Qt-interest] QRect::contains is lying to me

Scott Aron Bloom Scott.Bloom at sabgroup.com
Mon Dec 21 08:57:58 CET 2009


Its not lying.. its telling the truth...

At least of the example you are showing...

QRect::Contains( QRect) returns true if the second rectangle is 100%
contained by the first...

It looks like you want QRet::intersected

Scott

-----Original Message-----
From: qt-interest-bounces at trolltech.com
[mailto:qt-interest-bounces at trolltech.com] On Behalf Of Paul England
Sent: Sunday, December 20, 2009 9:33 PM
To: qt-interest at trolltech.com
Subject: [Qt-interest] QRect::contains is lying to me

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.
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest




More information about the Qt-interest-old mailing list