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

Paul England pengland at cmt-asia.com
Mon Dec 21 09:43:16 CET 2009


Ah, yes.  The specs can get you every time.
> Look at the docs again.. For the QRect::contains( QRect, bool )
> overload, it says:
> bool QRect::contains ( const QRect & rectangle, bool proper = false )
> const
> This is an overloaded function.
>
> Returns true if the given rectangle is inside this rectangle. otherwise
> returns false. If proper is true, this function only returns true if the
> rectangle is entirely inside this rectangle (not on the edge).
>
>
> I read that as, if the edges are the same, it returns false, otherwise
> it has to be fully contained... 
>
> Not if the other rect is partially contained.
>
> Scott
>
> -----Original Message-----
> From: qt-interest-bounces at trolltech.com
> [mailto:qt-interest-bounces at trolltech.com] On Behalf Of Paul England
> Sent: Monday, December 21, 2009 12:31 AM
> Cc: qt-interest at trolltech.com
> Subject: Re: [Qt-interest] QRect::contains is lying to me
>
> Hi Scott:
>
> >From the documentation, it returnd true when it's completely contained
> if you call QRect::contains( const QRect&, bool proper = false ). 
> Default is false.  Or maybe I'm reading that wrong?
>
> Another user suggested  intersects(), and it works much better, although
> not perfect.  I can sometimes drop a QTableWidget on to a subclassed
> QGroupBox.  Never the other way around though.  I've not poked hard
> enough to point any fingers yet, however, it's mostly working. :)
>
> Cheers for the help
> Paul
>
> Scott Aron Bloom wrote:
>   
>> 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
>>
>> _______________________________________________
>> Qt-interest mailing list
>> Qt-interest at trolltech.com
>> http://lists.trolltech.com/mailman/listinfo/qt-interest
>>   
>>     
>
> _______________________________________________
> Qt-interest mailing list
> Qt-interest at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-interest
>
> _______________________________________________
> 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