Results 1 to 19 of 19

Thread: timeline

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default timeline

    Hi to all, I'm developing an audio editor that at the moment has basic functionalities as draw the sound waveform, play the sound.
    I would implement a time line ( a moving vertical line ) that give to the user an idea of which part of the sound is playing.
    In the paintEvent I have to draw the waveform ( cached in a QImage ) and the time line.

    This is my paintEvent
    Qt Code:
    1. void WaveWidget::paintEvent( QPaintEvent* pe )
    2. {
    3. // Update the ev->rect area with the wave from the rendered QPixmap here
    4.  
    5. if( m_waveCachePixmap.isNull() )
    6. {
    7. updateWave();
    8. }
    9.  
    10. QPainter p( this );
    11. QPen pen = QPen(Qt::blue, 1);
    12. p.setRenderHint( QPainter::Antialiasing, true );
    13. p.drawImage( 0, 0, m_waveCachePixmap );
    14.  
    15. QRect& rect = QRect(pe->rect());
    16. p.setPen(pen);
    17.  
    18. p.drawLine( rect.x(), 0, rect.x(), height() );
    19. }
    To copy to clipboard, switch view to plain text mode 

    I also have to delete the previous line before to draw the new? Or the final result is a growing rectangle. How can I do?

    Best,
    Franco
    Franco Amato

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

    Default Re: timeline

    What exactly is the problem?
    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
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: timeline

    Quote Originally Posted by wysota View Post
    What exactly is the problem?
    Instead of drawing a horizzontally moving line it draw a rectangle that grow.
    Franco Amato

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

    Default Re: timeline

    The rect() you get in the paint event can be an arbitrary rectangle from within your widget's coordinates. I don't think you want to paint arbitrary rectangles on your widget...
    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
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: timeline

    Quote Originally Posted by wysota View Post
    The rect() you get in the paint event can be an arbitrary rectangle from within your widget's coordinates. I don't think you want to paint arbitrary rectangles on your widget...
    Sorry but I didn't get you.
    So what must I do? Where my code is wrong?
    Franco Amato

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

    Default Re: timeline

    Quote Originally Posted by franco.amato View Post
    So what must I do?
    Draw a line in coordinates you want it to be drawn at, not the ones passed to you by the event.

    Where my code is wrong?
    Here:
    Qt Code:
    1. QRect& rect = QRect(pe->rect());
    2. p.setPen(pen);
    3.  
    4. p.drawLine( rect.x(), 0, rect.x(), height() );
    To copy to clipboard, switch view to plain text mode 
    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
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: timeline

    Quote Originally Posted by wysota View Post
    Draw a line in coordinates you want it to be drawn at, not the ones passed to you by the event.



    Here:
    Qt Code:
    1. QRect& rect = QRect(pe->rect());
    2. p.setPen(pen);
    3.  
    4. p.drawLine( rect.x(), 0, rect.x(), height() );
    To copy to clipboard, switch view to plain text mode 
    Sorry but I don't understand you.
    How can I draw I line where I want whitout considering the rect()? How can I pass the coordinates of the line to the paintEvent?

    Can you explain to me?

    Best
    Franco Amato

  8. #8
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: timeline

    I solved it.
    The problem was the rect I passed to the paintEvent. It must completely contain the 2 lines ( old and new ). Something like this
    Qt Code:
    1. QRect r = QRect( old_line - 1, 0, new_line + 1, height() )
    To copy to clipboard, switch view to plain text mode 
    and pass r to the paintevent
    Qt Code:
    1. update( r )
    To copy to clipboard, switch view to plain text mode 

    Regards,
    Franco
    Franco Amato

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

    Default Re: timeline

    No, that's wrong as well. Take a window from another application and start moving it around over your widget. You will see it's getting messy.
    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.


  10. #10
    Join Date
    Nov 2007
    Location
    Italy
    Posts
    694
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: timeline

    Quote Originally Posted by wysota View Post
    No, that's wrong as well. Take a window from another application and start moving it around over your widget. You will see it's getting messy.
    So please let me know how must I do.


    Thank you
    Franco Amato

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

    Default Re: timeline

    Quote Originally Posted by franco.amato View Post
    So please let me know how must I do.
    I already told you - draw the line in a place where you want it drawn, not in a random place. The line has some logic behind it, right? Are you able to tell exactly where the line should be drawn at a specified arbitrary moment based on the state of the application?
    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.


Similar Threads

  1. Creating a graphic timeline
    By kaushal_gaurav in forum Qt Programming
    Replies: 2
    Last Post: 26th November 2012, 13:03

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.