Results 1 to 15 of 15

Thread: Problem with QScrollview and QPainter

  1. #1
    Join Date
    Feb 2006
    Posts
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Problem with QScrollview and QPainter

    Hi,
    Iam having a problem with the usage of QScrollView and QPainter.
    Iam using Qt 3.3.4 on a solaris machine. My application requires
    to parse a log file and generate graph from it. The problem is that
    the drawContents method is drawing the graph more than once because
    of which the graph is overwriting from the top once it has reached
    the area that has been set using resizeContents.

    I have also set the size based on the size of the file.
    But nothing has changed. Iam sending you the part of the code:

    Qt Code:
    1. void drawContents(QPainter *p,int cx,int cy,int cw,int ch)
    2. {
    3. //opens the file for reading
    4. //TextStream is created for reading
    5.  
    6. while(!stream.atEnd())
    7. {
    8. //Each line is read
    9. //parsing is done
    10. //Graph is drawn
    11. }
    12.  
    13. //file is closed
    14. resizeContents(7000,gy);
    15. //lines are drawn vertically to avoid erasing
    16. }
    To copy to clipboard, switch view to plain text mode 

    Note:: In the above program, gy is declared as "int" holds the y-coordinate
    till where the line is to be drawn.It is incremented by 20 each time in the
    loop.

    I have tried other options like resizing the contents before the drawContents , even in this case also the behaviour the same.

    So, Kindly help me out from this problem because of which my application
    got struck.

    Thanks in advance.

    with regards,
    Saida
    Last edited by wysota; 6th March 2006 at 10:23. Reason: Added code tags

  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: Problem with QScrollview and QPainter

    Quote Originally Posted by saida
    I have tried other options like resizing the contents before the drawContents , even in this case also the behaviour the same.
    Are you sure? That must be helpfull
    Where did you call resizeContents()?
    a life without programming is like an empty bottle

  3. #3
    Join Date
    Feb 2006
    Posts
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Problem with QScrollview and QPainter

    hi,
    Thanks for replying soon. Earlier I have called the resizeContents in the constructor with some area. Then I placed it based it on the size of the file that iam parsing, at the end of drawContents.
    It goes like this:

    Qt Code:
    1. class ScrollDemo::public QScrollView
    2. {
    3. public:
    4. void ScrollDemo(....)
    5. { }
    6.  
    7. protected:
    8. void drawContents(.....)
    9. {
    10. //here all the coding which I mentioned previously
    11.  
    12. //end of while loop
    13. //closing of the file
    14. long unsigned int kount1= kount*20+150;
    15. resizeContents(7000,kount1);
    16. }
    17. };
    To copy to clipboard, switch view to plain text mode 

    Note:: Here kount is the variable used to count the no.of lines that iam drawing on the Scroll area
    and each line is drawn by incrementing the y-coordinate by 20.
    Hence kount1 holds the total area that is to be resized.

    Another important thing that I would like to mention is that for small to medium sized files, this code is working perfectly. For large files, I couldn't find any solution.

    Eagerly waiting for ur reply,
    Saida.
    Last edited by wysota; 6th March 2006 at 10:22. Reason: Added code tags

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

    Default Re: Problem with QScrollview and QPainter

    You should read the contents of the file in some other method, because now each time the window redraws, the file is reread, which is a big overhead. After reading the file, you can set the proper size of the scrollview's viewport and the call update() which will in turn call drawContents and there you should draw the data which is already stored somewhere in your application.

  5. #5
    Join Date
    Feb 2006
    Posts
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Problem with QScrollview and QPainter

    Hi Wysota,

    Thanks for the information that u have given. The problem in this is that I need to draw the
    graph as and when I get the blocks in each line. And If I do these things outside the drawContents method, I need to store the blocknames, signal name, positions of the blocks from where I need to draw the lines in the graph, which will be a tough task.
    Because, the best way of storing all this is again a file which i need to open again in drawContents method.
    sorry if I couldn't understand your suggestion. If it is so, please be more clear ( like show me the outline of the code that u want me to follow ).

    Thanks once again,
    saida.

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

    Default Re: Problem with QScrollview and QPainter

    The best way of storing things is in data structures, such as a list of classes or whatever. Files are too slow for that. If you want to read the file each time the widget is redrawn, you'll end up reading that file all the time.

    When the contents change, just reread the file once to update your data structures and then tell the widget to update itself and in drawContents just use that stored data to draw your widget.

  7. #7
    Join Date
    Feb 2006
    Posts
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Problem with QScrollview and QPainter

    hi wysota,
    I followed what you have suggested. Now it is responding little fast. My problem is that the application is drawing the graph multiple times. Because of this, it is drawing the contents from the top once it has reached the end of scroll area that has been set using resizeContents(). This time I have changed the code as:

    Qt Code:
    1. class ScrollViewDemo : public QScrollView
    2. {
    3. public :
    4. ScrollViewDemo(...)
    5. {
    6. //parsing of the file
    7. //resizeContents( width, height );
    8. updateContents(0 , 0 , width, height );
    9. }
    10.  
    11. protected:
    12. void drawContents(.....)
    13. {
    14. // drawing of the graph using the values stored in the variables
    15. }
    16. };
    To copy to clipboard, switch view to plain text mode 

    Not:e: If I comment the updateContents() line, I couldnot find any change in the graph.

    Kindly help me out of this problem.

    Thanks a lot,
    saida
    Last edited by wysota; 6th March 2006 at 10:21. Reason: Added code tags

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

    Default Re: Problem with QScrollview and QPainter

    Quote Originally Posted by saida
    My problem is that the application is drawing the graph multiple times. Because of this, it is drawing the contents from the top once it has reached the end of scroll area that has been set using resizeContents().
    Could you explain a bit more? How does it draw from the top once it reaches the end of scroll area? A screenshot would be nice...

  9. #9
    Join Date
    Feb 2006
    Posts
    5
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Problem with QScrollview and QPainter

    Wyosta,
    Iam sending you the snapshots of the graph that is a part of my application.

    I am sending you three snapshots:

    1) The first one is the graph generated for a small file and is perfect
    without any problem. (small.gif)
    2) The second one is for a big file where the overlap is shown. (large1.gif)
    3) The third one is also the graph generated for the above file and shows the
    position where it is drawing for the second time. From here, the graph is
    redrawn and continues from the top once it has reached the end of area that
    has been set. (large2.gif)

    Kindly read the format of the code (which I have sent previously) before seeing
    these snaps for clear idea of my problem.

    One more thing I would like to know is that Iam setting the area as:

    long unsigned int kount1=(kount*20)+150;
    resizeContents(7000,kount1);

    where kount holds the no.of lines that are to be represented on the graph.And each line
    is drawn by incrementing the y-coordinate by 20. And I saw the syntax of resizeContents
    where the parameters are integers. So, can you tell me would there be any problem
    with above usage. ( kount is declared as "int" only)


    I'll be waiting for your reply.

    Thanks,
    saida.
    Attached Images Attached Images

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

    Default Re: Problem with QScrollview and QPainter

    Could you show the code used for plotting the graph? I mean the contents of the loop which originally was:

    Qt Code:
    1. while(!stream.atEnd())
    2. {
    3. //Each line is read
    4. //parsing is done
    5. //Graph is drawn
    6. }
    To copy to clipboard, switch view to plain text mode 

    Especiall that "graph is drawn" part

  11. #11
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Problem with QScrollview and QPainter

    Sir,
    Thanks once again for your immediate response. well, the parsing is done on what we call the log files and each line of the file contains different blocks which are shown over the gray line in the snaps. And the code is somewhat big(over 600 lines). And you also need the files to understand the code and the graph that has been generated. Shall I send a sample file( whose graph is sent previously:: small.gif )?

    Important thing to note is that Iam able to get the graph for small files but not for larger ones.

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

    Default Re: Problem with QScrollview and QPainter

    It would be best if you sent a compilable example with example data so that I could compile and run it on my machine.

  13. #13
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Problem with QScrollview and QPainter

    That would be better. Iam sending you again two files and the complete code. These are the files that iam sending:

    small.txt (that contains the small file for which small.gif is sent).
    large.txt ( that contains the large file for which large.gif is sent) and
    source.cpp ( where the code has been written).

    Note: The "/tmp/parsetext.txt " in the code at any time contains the file for which graph has to be generated. And sir, I have not changed the code as you said previously (reading the file in another method). I have tried that but I faced the same problem of over-writing for large files. Kindly take time to see this and help me in what ever way possible.

    Thanks alot for your co-operation.
    with regards,
    sarma.
    Attached Files Attached Files

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

    Default Re: Problem with QScrollview and QPainter

    Ok, I think I might have found your problem. As far as I remember there exists a maximum size of a widget under X11. I don't remember the exact size, but it's probably around 64k (or less) and I see you are trying to obtain greater heights which probably causes an overflow of some variable resulting in y values being y = kount1 % maxheight.

    So having found the bug is one thing, but working it around is another. In your case, you can either switch to Qt4 (which, afair has a workaround for this) or make a fake scrollview. Instead of having a very big viewport, have a regular widget which will change its contents according to scrollbar values. Meaning you'll have to implement paintEvent in such a way, that is renders only a part of your chart which should currently be visible. You could also check if QCanvasView has the same limitations.

    A side effect will be that your widget should redraw much faster.
    Last edited by wysota; 6th March 2006 at 17:13.

  15. #15
    Join Date
    Mar 2006
    Location
    Hyderabad
    Posts
    69
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt3
    Platforms
    Unix/X11

    Default Re: Problem with QScrollview and QPainter

    Sir,
    What you said might be correct. But Iam a novice in QtProgramming. So I don't know how to fix this problem . I shall be greatful to you if you help me in this regard.This is the only problem that Iam having since 3 weeks. Presently Iam trying it with QCanvasView.

    Thanks alot,
    Sarma.

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.