Results 1 to 10 of 10

Thread: Confusion with QPoint

  1. #1
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Red face Confusion with QPoint

    hello there i have a function called position which is inside another class called shapeItem( ) and it returns a QPoint, but when i do the following it brings up an error saying left hand of operator has no effect. the code is listed below:

    1. QPoint mid = shapeItem.position();

    where, shapeItem.position is of the following:

    2. QPoint ShapeItem:osition() const
    3. {
    4. return myPosition;
    5. }

    any idea's on how to make QPoint mid obtain the value from the position function??? any input would be much appreciated thanks. Jag

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Confusion with QPoint

    Could you post the exact error message?

  3. #3
    Join Date
    Jan 2006
    Location
    Belgium
    Posts
    99
    Thanks
    1
    Thanked 3 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Confusion with QPoint

    sounds like you are using shapeItem instead of ShapeItem or vice versa.

    Most of the time your code will be more readable if your objects don't have the same name as the class (only different in capitals). You could use Itm or something similar.

    Cheers

  4. #4
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Confusion with QPoint

    here is the rest of the error message - hope this helps:

    sortingbox.cpp: In member function `virtual void SortingBox:aintEvent(QPaintEv
    ent*)':
    sortingbox.cpp:125: warning: left-hand operand of comma has no effect
    sortingbox.cpp:125: error: no matching function for call to `QRect::QRect(QPoint
    &, int, QString)'
    C:/Qt/4.0.1/include/QtCore/../../src/corelib/tools/qrect.h:37: note: candidates
    are: QRect::QRect(const QRect&)
    C:/Qt/4.0.1/include/QtCore/../../src/corelib/tools/qrect.h:183: note:
    QRect::QRect(int, int, int, int)
    C:/Qt/4.0.1/include/QtCore/../../src/corelib/tools/qrect.h:199: note:
    QRect::QRect(const QPoint&, const QSize&)
    C:/Qt/4.0.1/include/QtCore/../../src/corelib/tools/qrect.h:191: note:
    QRect::QRect(const QPoint&, const QPoint&)
    C:/Qt/4.0.1/include/QtCore/../../src/corelib/tools/qrect.h:39: note:
    QRect::QRect()

  5. #5
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Confusion with QPoint

    How did you declare that shapeItem variable?

  6. #6
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Confusion with QPoint

    basically what i am wanting to do is display a number inside a circle which gets displayed at shapteItem.position(). my code for the displaying of the circes is like below:

    QPainter painter(this);

    foreach (ShapeItem shapeItem, shapeItems)
    {
    QPoint text(100,100);
    QPoint mid(shapeItem.position())

    painter.translate(shapeItem.position());
    painter.setBrush(shapeItem.color());
    painter.drawPath(shapeItem.path());
    painter.translate(-shapeItem.position());
    painter.setPen(initialItemColor());
    painter.drawText(QRect(mid,text),0,tr("%1").arg(sh apeItem.instanceNumber()));

    }

    ShapeItem is a class in another fle named ShapeItem.cpp and the shapeItem.position was decared in the header file as :

    void setPosition(const QPoint &position); and QPoint position() const; where the QPoint is a private variable. my function inside shapeItem is then as follows:

    QPoint ShapeItem:osition() const
    {
    return myPosition;
    }

    and:

    void ShapeItem::setPosition(const QPoint &position)
    {
    myPosition = position;
    }

    hope that helps, cheers

  7. #7
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Confusion with QPoint

    All looks OK here.

    Is that the first error you get?

  8. #8
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Unhappy Re: Confusion with QPoint

    i got it to work using the following code: QPoint mid(shapeItem.position()); but it doesnt display anything on the screen for some bizarre reason when i try to draw it with this:

    painter.setPen(initialItemColor());
    painter.drawText(QRect(mid,text),0,tr("%1").arg(sh apeItem.instanceNumber()));

    i think its a lost hope cos i cant think of aything else to use???!!

  9. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Confusion with QPoint

    What does this output?
    Qt Code:
    1. painter.setPen( initialItemColor() );
    2. QRect r(mid,text);
    3. qWarning( "x=%d y=%d w=%d h=%d", r.x(), r.y(), r.width(), r.height() );
    4. painter.drawText( r, QString::number( shapeItem.instanceNumber() ) );
    To copy to clipboard, switch view to plain text mode 

  10. #10
    Join Date
    Feb 2006
    Posts
    87
    Thanks
    6
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: Confusion with QPoint

    i managed to get it working. i was kinda simple in the end, maybe i wasnt explaining my problem properly. all i did was just change the parameters for the drawText function. to the following:

    painter.drawText((shapeItem.position( )),tr("%1").arg(shapeItem.instanceNumber()));


    thanks for your help - much appreciated. Jag

Similar Threads

  1. Little confusion Regarding general Initilizaion..!!!
    By kunalnandi in forum General Programming
    Replies: 19
    Last Post: 11th October 2008, 12:29
  2. Little confusion Regarding general Initilizaion.. :confused:
    By kunalnandi in forum General Programming
    Replies: 2
    Last Post: 19th September 2008, 10:06
  3. QPoint Limitation
    By archanasubodh in forum Qt Programming
    Replies: 1
    Last Post: 5th August 2008, 10:22
  4. How find QPoint from a QListWidgetItem inside viewport?
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 12th April 2008, 12:28
  5. QTableView paints too much
    By Jimmy2775 in forum Qt Programming
    Replies: 2
    Last Post: 26th July 2006, 18:42

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.