Results 1 to 3 of 3

Thread: issue with drawLines

  1. #1
    Join Date
    Jul 2010
    Posts
    72
    Thanks
    35
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default issue with drawLines

    Hi everyone,

    I have been having a problem using QPainter. I would like to be able to draw lines whose coordinates (x0,y0,x1,y1) are defined outside the paintEvent. I have set the values of this coordinates at the constructor of the Label, where I will be carrying the drawing. Hence, on the constructor of the label I initialized the values for the line coordinates and a QImage that I will be also drawing in the paintEvent. The problem is that only the Image appears on the label and there is no line. However, if on the code below I type drawLine(10,10,50,50) instead of drawLine(x0,y0,x1,y1) the line will actually be drawn (but, of course, I don't want to do this). Are there any suggestions on how to solve this problem? Thank you.

    Here is the code for the Label:


    class main_Graphics_Label : public QLabel
    {
    Q_OBJECT
    public:

    QImage ImageP;
    int x0,y0,x1,y1;

    main_Graphics_Label(QWidget *parent = 0) : QLabel(parent)
    {
    ImageP = QImage(200, 200, QImage::Format_ARGB32);
    ImageP.fill(qRgb(0, 0, 255 ));
    x0=10;
    y0=10;
    x1=50;
    y1=50;
    }

    void paintEvent(QPaintEvent *e)
    {
    QPainter painter(this);
    painter.drawImage(1,1, ImageP);
    painter.drawLine(x0,y0,x1,y1);
    }


    };

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: issue with drawLines

    Can you verify the coordinates?
    e.g. in paintEvent()
    Qt Code:
    1. qDebug() << x0 << y0 << x1 << y1;
    To copy to clipboard, switch view to plain text mode 

    Cheers,
    _

  3. The following user says thank you to anda_skoa for this useful post:

    Maluko_Da_Tola (1st November 2013)

  4. #3
    Join Date
    Jul 2010
    Posts
    72
    Thanks
    35
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: issue with drawLines

    Thanks, the coordinates were assigned completely cray values:

    323144952 1644674568 -2013265920 0

    Why is this happening? Shouldn't their value be defined at the constructor of the main_Graphics_Label ?


    Added after 1 28 minutes:


    The code works now. I went to have some lunch and, when I returned, the code was simply working. Thanks for the help anyways
    Last edited by Maluko_Da_Tola; 1st November 2013 at 13:28.

Similar Threads

  1. Qt 5.0.1 Issue
    By kiboi in forum Qt-based Software
    Replies: 0
    Last Post: 22nd March 2013, 05:22
  2. Qt 4.7.1 VNC issue?
    By djstava in forum Newbie
    Replies: 0
    Last Post: 14th March 2011, 03:34
  3. XML issue
    By jbpvr in forum Qt Programming
    Replies: 1
    Last Post: 25th August 2008, 13:01
  4. UI issue.
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 13th August 2008, 11:41
  5. ui_....h issue
    By stevey in forum Qt Programming
    Replies: 5
    Last Post: 27th November 2007, 04:54

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.