Results 1 to 5 of 5

Thread: Line not being created

  1. #1
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Line not being created

    Hi...

    I am trying to create a line on canvas but it is not being displayed.. i dont understand why it is not getting created... i had created applications using the same idea and they were being created... here it is not the case.. Am i missing something...

    Qt Code:
    1. void ImageDraw::drawLine(QPoint point1, QPoint point2)
    2. {
    3. int xxPoint,xyPoint,yxPoint,yyPoint;
    4. m_pCanvasLine = new Q3CanvasLine(m_pCanvas);
    5. xxPoint = point1.x();
    6. xyPoint = point1.y();
    7. yxPoint = point2.x();
    8. yyPoint = point2.y();
    9. m_pCanvasLine->setPoints(xxPoint,xyPoint,yxPoint,yyPoint);
    10. m_pCanvasLine->show();
    11. resizeContents(400,400);
    12. }
    To copy to clipboard, switch view to plain text mode 

    here m_pCanvas is a Canvas Object...

    Thank you

    Kapil

  2. #2
    Join Date
    Jan 2006
    Location
    Ukraine,Lviv
    Posts
    454
    Thanks
    9
    Thanked 27 Times in 27 Posts
    Qt products
    Qt3
    Platforms
    Unix/X11 Windows

    Default Re: Line not being created

    You must first draw it. Use draw() method
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Line not being created

    Hi...

    draw() methos uses QPainter object but i have to create the line on the canvas...

    I went thru the document of QCanvasLine and also the example canvas example on it...

    It also does not use the draw() method..

    Also i created a simple independent application wherein i just create a canvas and draw a line and it is being created.. its just here where its causing the problem and am not able to make it out why....

    Thanks..

    Kapil

  4. #4
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Line not being created

    Hi..

    I deleted all my code and tried again but still its not happening.. i have no clue what can be the reason for non-creation of a line on the canvas... I am putting on the code.. Please help me to sort out the error...

    canvasmouse.h
    Qt Code:
    1. #ifndef CANVASMOUSE_H
    2. #define CANVASMOUSE_H
    3.  
    4. #include "ui_zoomsample.h"
    5. #include <Q3CanvasView>
    6. #include <Q3Canvas>
    7. #include <Qt>
    8. #include <QtGui>
    9. #include <Q3CanvasLine>
    10.  
    11. class CanvasMouse: public Q3CanvasView
    12. {
    13. Q_OBJECT
    14.  
    15. public:
    16. CanvasMouse(Q3Canvas *pCanvas,QFrame *frame);
    17. ~CanvasMouse();
    18.  
    19. private:
    20.  
    21. void drawLine();
    22. Q3Canvas *m_pCanvas;
    23. Q3CanvasLine *m_pCanvasLine;
    24. };
    25.  
    26. #endif
    To copy to clipboard, switch view to plain text mode 

    canvasmouse.cpp
    Qt Code:
    1. #include "canvasmouse.h"
    2. CanvasMouse::CanvasMouse(Q3Canvas *pCanvas, QFrame *frame): Q3CanvasView(frame)
    3. {
    4. m_pCanvas = pCanvas;
    5. Q3CanvasView::setCanvas(m_pCanvas);
    6. m_pCanvas->setBackgroundColor(Qt::white);
    7. Q3CanvasView::resize(400, 400);
    8. drawLine();
    9. }
    10. CanvasMouse::~CanvasMouse()
    11. {
    12. }
    13. void CanvasMouse::drawLine()
    14. {
    15. m_pCanvasLine = new Q3CanvasLine(m_pCanvas);
    16. m_pCanvasLine->setPoints(10,10,100,10);
    17. m_pCanvasLine->show();
    18. resizeContents(400,400);
    19. }
    To copy to clipboard, switch view to plain text mode 

    main.cpp
    Qt Code:
    1. #include <QApplication>
    2. #include "imagezoomer.h"
    3. #include "ui_zoomsample.h"
    4.  
    5. int main(int argc, char **argv)
    6. {
    7. QApplication app(argc,argv);
    8. QMainWindow *form = new QMainWindow;
    9.  
    10. Ui::MainWindow *ui;
    11. ui = new Ui::MainWindow();
    12. ui->setupUi(form);
    13. Q3Canvas *pCanvas = new Q3Canvas;
    14. ImageZoomer imgzoom(ui,pCanvas);
    15. form->show();
    16. return app.exec();
    17. }
    To copy to clipboard, switch view to plain text mode 

    imagezoomer.h
    Qt Code:
    1. #include "imagezoomer.h"
    2. #include <QtGui>
    3. #include <qdir.h>
    4. #include <QColor>
    5.  
    6. ImageZoomer::ImageZoomer(Ui::MainWindow *_mwin, Q3Canvas *pCanvas): mwin(_mwin),m_pCanvas(pCanvas)
    7. {
    8. frame = new QFrame(mwin->centralwidget);
    9. frame->setGeometry(QRect(60, 70, 591, 571));
    10. frame->setFrameShape(QFrame::StyledPanel);
    11. frame->setFrameShadow(QFrame::Plain);
    12.  
    13. canmouse = new CanvasMouse(m_pCanvas,frame);
    14. }
    15. ImageZoomer::~ImageZoomer()
    16. {
    17. }
    To copy to clipboard, switch view to plain text mode 

    There is no compilation error.. It has to be somewhere logical... and i am not able to catch it.. Please help me in finding it out..

    Thanking you...

    Kapil

  5. #5
    Join Date
    Feb 2006
    Location
    New Delhi,India
    Posts
    226
    Thanks
    14
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Line not being created

    Hi..

    I got the solution ... I was not the calling the canvas->resize() function...
    Now it is executing pretty fine...

    Kapil

Similar Threads

  1. QTcpSocket exception.
    By Fastman in forum Qt Programming
    Replies: 9
    Last Post: 29th January 2008, 13:51
  2. Some very weird compilation warnings
    By MarkoSan in forum Qt Programming
    Replies: 21
    Last Post: 23rd January 2008, 16:48
  3. Qwizard crashed when created in a slot
    By joshlareau in forum Qt Programming
    Replies: 9
    Last Post: 15th January 2008, 09:16
  4. KDE/QWT doubt on debian sarge
    By hildebrand in forum KDE Forum
    Replies: 13
    Last Post: 25th April 2007, 06:13
  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.