Results 1 to 4 of 4

Thread: Drawing user defined images and displaying on buttons

  1. #1
    Join Date
    Dec 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Drawing user defined images and displaying on buttons

    Hi ,
    Iam new tothe QT programming.Please suggest me with code snippet how to draw images of our choice.iam totally new to the QT.Iam using QT 4.5.please find the image as attachment.

    My task is,

    I need to draw the attached image and display it on the button and once i click the button that image should display on the screen.I have gone through diagramscene example,it is of no use for me as it contains only polygons,i want to draw image of my choice.Please suggest me with the code snippet.

    Thanks in advance.

    Sudhir
    Attached Images Attached Images

  2. #2
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Drawing user defined images and displaying on buttons

    I need to draw the attached image and display it on the button
    You might find the QAbstractButton helpful.
    Look at the setIcon() method.

    and once i click the button that image should display on the screen.
    QLabel comes to mind.
    Have a look at QLabel::setPixmap() .
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

  3. #3
    Join Date
    Dec 2009
    Posts
    2
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Drawing user defined images and displaying on buttons

    high_flyer thanks for the reply , ur suggestions helped me upto some extent.

    can u suggest me in solving my main problem................... Thanks in advance


    This is my Code,

    #include <QtGui>
    #include "diagramitem.h"
    #include "arrow.h"

    DiagramItem:iagramItem(DiagramType diagramType, QMenu *contextMenu,
    QGraphicsItem *parent, QGraphicsScene *scene)
    : QGraphicsPolygonItem(parent, scene)
    {
    myDiagramType = diagramType;
    myContextMenu = contextMenu;

    QPainterPath path;
    switch (myDiagramType) {
    case StartEnd:
    path.moveTo(200, 50); path.arcTo(150, 0, 50, 50, 0, 90);
    path.arcTo(50, 0, 50, 50, 90, 90); path.arcTo(50, 50, 50, 50, 180, 90);
    path.arcTo(150, 50, 50, 50, 270, 90); path.lineTo(200, 25);
    myPolygon = path.toFillPolygon();
    break;
    case Conditional:
    // path.moveTo(-60.0, -10.0);
    path.lineTo(-40.0, 0.0);
    path.moveTo(0,0);
    path.lineTo(0,-40);
    path.moveTo(0,0);
    path.lineTo(0,40);

    myPolygon = path.toFillPolygon();
    //myPolygon << QPointF(0, 63) << QPointF(0, -63);
    break;
    case Step:
    myPolygon << QPointF(-100, 100)<< QPointF(-100, -100);
    break;
    default:
    // input/output
    myPolygon << QPointF(-63, 0) << QPointF(63, 0);
    break;
    }
    setPolygon(myPolygon);
    setFlag(QGraphicsItem::ItemIsMovable, true);
    setFlag(QGraphicsItem::ItemIsSelectable, true);
    }


    QPixmap DiagramItem::image() const
    {
    QPixmap pixmap(250, 250);
    pixmap.fill(Qt::transparent);
    QPainter painter(&pixmap);
    painter.setPen(QPen(Qt::black, 12));
    painter.translate(125, 125);
    painter.drawPolyline(myPolygon);

    return pixmap;
    }

    The problem is , when iam going with path.toFillPolygon(); the start and end points are getting joined.i want to draw the attached image .

  4. #4
    Join Date
    Jan 2006
    Location
    Munich, Germany
    Posts
    4,714
    Thanks
    21
    Thanked 418 Times in 411 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows

    Default Re: Drawing user defined images and displaying on buttons

    just do setIcon(), the button will do the drawing for you.
    ==========================signature=============== ==================
    S.O.L.I.D principles (use them!):
    https://en.wikipedia.org/wiki/SOLID_...iented_design)

    Do you write clean code? - if you are TDD'ing then maybe, if not, your not writing clean code.

Similar Threads

  1. QSqlQueryModel + user defined roles
    By NoRulez in forum Qt Programming
    Replies: 1
    Last Post: 7th December 2009, 07:29
  2. Resizing user defined QGraphicsItem
    By manti_madhu in forum Qt Programming
    Replies: 0
    Last Post: 9th September 2009, 09:35
  3. Using User Defined Libraries
    By csvivek in forum Qt Programming
    Replies: 1
    Last Post: 27th May 2008, 19:47
  4. User Defined Signal?
    By rajeshs in forum Newbie
    Replies: 2
    Last Post: 18th December 2007, 11:42
  5. How to suppress user defined events in processEvents()
    By Artschi in forum Qt Programming
    Replies: 5
    Last Post: 5th July 2007, 10:17

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.