Results 1 to 10 of 10

Thread: Need Some help with QPainter.

  1. #1
    Join Date
    Jul 2012
    Posts
    201
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Need Some help with QPainter.

    Hi there guys, this is what I have done with QPainter Image 6.jpg and this is what I am aiming for pg5.png.
    Here is my code below.
    Qt Code:
    1. path.moveTo(150, 200);
    2. path.quadTo(150, 150, 200, 150);
    3. path.lineTo(402, 150);
    4.  
    5. path.lineTo(402, 400);
    6. path.quadTo(402, 450, 350, 450);
    7. path.lineTo(150, 450);
    8.  
    9. path.closeSubpath();
    10.  
    11. painter->setPen(pen);
    12. painter->drawImage(boundingRect(), image);
    13. painter->drawPath(path);
    To copy to clipboard, switch view to plain text mode 
    My problem here is that I don't know how to remove the image corners popping out at the top-left hand corner and the bottom-right hand corner. All I did was to draw the paintPath over the edges of the image. I am not ever sure if that should have been the approach.

    Any help will be greatly appreciated.

    thank you.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Need Some help with QPainter.

    Set clipping on the painter before you draw the image or use a composition mode that will draw on an area specified by a given mask.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Jul 2012
    Posts
    201
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Re: Need Some help with QPainter.

    Thank you, I can't believe how easy that was. I have small problem with this GraphicsItem. I have set the flag to make the item movable, but the item wont move when dragged. Could it be because the item is a child item to another item? Here is the code below.
    Qt Code:
    1. Picture::Picture(QRectF itemRect)
    2. {
    3. rect = itemRect;
    4.  
    5. setFlag(QGraphicsItem::ItemIsMovable);
    6. setFlag(QGraphicsItem::ItemIsSelectable);
    7. setFlag(QGraphicsItem::ItemIsFocusable);
    8.  
    9. pixmap = new QPixmap();
    10. }
    To copy to clipboard, switch view to plain text mode 
    and the code below is where i initialize the object in the main function.
    Qt Code:
    1. photo = new Picture(QRectF(150,150,252,300));
    2. photo->setPicDir(":/TestPics/Test_images/myPic.jpg");
    3. photo->setParentItem(page_1);
    4. photo->setPainterID(1);
    5. scene->addItem(photo);
    To copy to clipboard, switch view to plain text mode 
    Am I doing something wrong here?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Need Some help with QPainter.

    Did you reimplement any mouse events (e.g. in the view)?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Jul 2012
    Posts
    201
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Re: Need Some help with QPainter.

    Yes I did, but in the scene class and the mouseEvent function I implemented has no relationship with the graphicsItem I am trying move around the scene. The mouse event function that I implemented is specifically for handling where to insert a QGraphicstextItem in the scene. here is the code below
    Qt Code:
    1. void Scene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent)
    2. {
    3. if (mouseEvent->button() != Qt::LeftButton)
    4. return;
    5.  
    6. textItem = new TextItem();
    7.  
    8. textItem->setFont(myFont);
    9. textItem->setTextInteractionFlags(Qt::TextEditorInteraction);
    10. textItem->setZValue(1000.0);
    11. connect(textItem, SIGNAL(lostFocus(TextItem*)),
    12. this, SLOT(editorLostFocus(TextItem*)));
    13. connect(textItem, SIGNAL(selectedChange(QGraphicsItem*)),
    14. this, SIGNAL(itemSelected(QGraphicsItem*)));
    15. addItem(textItem);
    16. textItem->setDefaultTextColor(myTextColor);
    17. textItem->setPos(mouseEvent->scenePos());
    18. emit textInserted(textItem);
    19.  
    20. QGraphicsScene::mousePressEvent(mouseEvent);
    21. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Need Some help with QPainter.

    Quote Originally Posted by ayanda83 View Post
    Yes I did, but in the scene class and the mouseEvent function I implemented has no relationship with the graphicsItem I am trying move around the scene.
    But it breaks the built-in move functionality. Make sure the default implementation of all mouse events is always executed if you want items to be movable.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jul 2012
    Posts
    201
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Re: Need Some help with QPainter.

    Quote Originally Posted by wysota View Post
    But it breaks the built-in move functionality. Make sure the default implementation of all mouse events is always executed if you want items to be movable.
    Thank you for your reply but I am not sure about how to go about ensuring that the default implementation of all mouse events is always executed. Could you further elaborate on this if you don't mind please. Does it mean I must not implement mouse event functions or what?

  8. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,373
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: Need Some help with QPainter.

    Quote Originally Posted by ayanda83 View Post
    Could you further elaborate on this
    This is not C++ kindergarden.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  9. #9
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,346
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    318
    Thanked 872 Times in 859 Posts

    Default Re: Need Some help with QPainter.

    This is not C++ kindergarden.
    To elaborate, if you derive from a class, how do you ensure that when you override a virtual method for that class that the base class (default) method also gets executed? It's taught in C++ preschool...

  10. #10
    Join Date
    Jul 2012
    Posts
    201
    Qt products
    Qt4
    Platforms
    Windows
    Thanks
    26
    Thanked 1 Time in 1 Post

    Default Re: Need Some help with QPainter.

    Quote Originally Posted by wysota View Post
    This is not C++ kindergarden.
    I am familiar with Polymorphism; I was just a little confused by your reply. I didn't know that you were talking about Polymorphism but thanks to "d_stranz" for explaining a little, now I understand what you meant. And thanks to you wysota, you are always helpful and sorry for the misunderstanding.

Similar Threads

  1. Replies: 2
    Last Post: 26th December 2012, 02:03
  2. QPainter(&QPrinter) & QPainter(&QImage) communication
    By gufeatza in forum Qt Programming
    Replies: 2
    Last Post: 2nd February 2010, 08:25
  3. Replies: 5
    Last Post: 7th September 2009, 21:57
  4. QPainter::save and QPAinter::restore()
    By quickNitin in forum Newbie
    Replies: 2
    Last Post: 17th June 2006, 23:11
  5. Replies: 3
    Last Post: 30th April 2006, 20:22

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
  •  
Qt is a trademark of The Qt Company.