Results 1 to 17 of 17

Thread: About QScroll Area

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

    Default About QScroll Area

    Hi to all, I attached a widget to a QScrollArea. Such widget has a moving timeline. I would keep the timeline visible when moving,
    This mean that when the timeline come to the end of the widget the whole scrollarea should be shifted to the left. I don't know how to do it.

    I hope to get help.

    Best Regards,
    Franco
    Franco Amato

  2. #2
    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: About QScroll Area

    Set value of the horizontal scroll bar of the scroll area to 0.
    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
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: About QScroll Area

    Quote Originally Posted by wysota View Post
    Set value of the horizontal scroll bar of the scroll area to 0.

    Hi it doesn't work...when the time line comes at the end of the viewport it disappear and nothing happens
    Franco Amato

  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: About QScroll Area

    Please provide a minimal compilable example reproducing 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.


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

    Default Re: About QScroll Area

    Quote Originally Posted by wysota View Post
    Please provide a minimal compilable example reproducing the problem.
    Qt Code:
    1. WaveWidget::WaveWidget( QWidget* parent /* = 0 */ )
    2. : QWidget( parent ),
    3. m_wave(0),
    4. m_ZoomFactor( 1.0 )
    5. {
    6. /* scroll area */
    7.  
    8. sa->setWidgetResizable(true);
    9. QScrollBar *scrollBar = sa->horizontalScrollBar();
    10. scrollBar->setSliderDown( true );
    11. scrollBar->setValue(0);
    12. sa->setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff);
    13. sa->setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOn);
    14.  
    15. m_WaveDisplay = new WaveDisplay(sa->viewport());
    16. m_WaveDisplay->setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Ignored);
    17. sa->setWidget( m_WaveDisplay );
    18.  
    19.  
    20. QHBoxLayout* hl = new QHBoxLayout();
    21. hl->addWidget(m_panel);
    22. hl->setSpacing( 0 );
    23. hl->addWidget(sa);
    24.  
    25. QVBoxLayout* layout = new QVBoxLayout();
    26. layout->addLayout(hl);
    27. layout->addLayout(lo);
    28. setLayout(layout);
    29. setFocusPolicy( Qt::TabFocus );
    30. }
    To copy to clipboard, switch view to plain text mode 

    m_WaveDisplay is a waveform display and when I click "play" a time line moves over it. When the timeline reach the end of the visible part it disappear on the right. I would shift the viewport() to keep visible ihe timeline.

    I hope it's clear
    Last edited by franco.amato; 23rd January 2010 at 20:08.
    Franco Amato

  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: About QScroll Area

    That's neither compilable nor reproducing the problem...

    Anyway, this works for me (and this is what I mean by a minimal compilable example):
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class ScrollArea : public QScrollArea {
    4. public:
    5. ScrollArea() : QScrollArea(){}
    6. protected:
    7. void timerEvent(QTimerEvent *te){
    8. int v = horizontalScrollBar()->value();
    9. int m = horizontalScrollBar()->maximum();
    10. if(v==m)
    11. horizontalScrollBar()->setValue(0);
    12. else
    13. horizontalScrollBar()->setValue(v+1);
    14. }
    15. };
    16.  
    17. int main(int argc, char **argv){
    18. QApplication app(argc, argv);
    19. QLabel *label = new QLabel;
    20. QPixmap px(2048, 60);
    21. QLinearGradient grad(0,0,2048,0);
    22. grad.setColorAt(0, Qt::red);
    23. grad.setColorAt(1, Qt::blue);
    24. QPainter p(&px);
    25. p.fillRect(px.rect(), QBrush(grad));
    26. p.end();
    27. label->setPixmap(px);
    28. ScrollArea area;
    29. area.setWidget(label);
    30. area.show();
    31. area.startTimer(10);
    32. return app.exec();
    33. }
    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
    691
    Thanks
    59
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Thumbs up Re: About QScroll Area

    Quote Originally Posted by wysota View Post
    That's neither compilable nor reproducing the problem...

    Anyway, this works for me (and this is what I mean by a minimal compilable example):
    Qt Code:
    1. #include <QtGui>
    2.  
    3. class ScrollArea : public QScrollArea {
    4. public:
    5. ScrollArea() : QScrollArea(){}
    6. protected:
    7. void timerEvent(QTimerEvent *te){
    8. int v = horizontalScrollBar()->value();
    9. int m = horizontalScrollBar()->maximum();
    10. if(v==m)
    11. horizontalScrollBar()->setValue(0);
    12. else
    13. horizontalScrollBar()->setValue(v+1);
    14. }
    15. };
    16.  
    17. int main(int argc, char **argv){
    18. QApplication app(argc, argv);
    19. QLabel *label = new QLabel;
    20. QPixmap px(2048, 60);
    21. QLinearGradient grad(0,0,2048,0);
    22. grad.setColorAt(0, Qt::red);
    23. grad.setColorAt(1, Qt::blue);
    24. QPainter p(&px);
    25. p.fillRect(px.rect(), QBrush(grad));
    26. p.end();
    27. label->setPixmap(px);
    28. ScrollArea area;
    29. area.setWidget(label);
    30. area.show();
    31. area.startTimer(10);
    32. return app.exec();
    33. }
    To copy to clipboard, switch view to plain text mode 
    Dear Wysota I solved my problem using ensureVisible routine of the QScrollArea http://doc.trolltech.com/4.6/qscroll...#ensureVisible givind periodically the position of the timeline and it works perfectly.
    This routine is fantastic!!

    Best Regards
    Franco Amato

  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: About QScroll Area

    That's the second time you "solved" your problem the wrong way. Keep doing that and at some point everything will fall apart.
    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.


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

    Default Re: About QScroll Area

    Quote Originally Posted by wysota View Post
    That's the second time you "solved" your problem the wrong way. Keep doing that and at some point everything will fall apart.
    Why wrong way? Seems work well. I don't have to set to zero the scroll bar, I would keep visible the timeline
    Franco Amato

  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: About QScroll Area

    Quote Originally Posted by franco.amato View Post
    Why wrong way? Seems work well.
    Many things seem well but you shouldn't use them as at some point the combination of things that seem to work fell will blow up into your face.

    I don't have to set to zero the scroll bar,
    Honestly, you don't have to do anything...

    I would keep visible the timeline
    Did you run my example? Did you see the gradient vanishing after reaching the end? Maybe things are already exploding in your face...
    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.


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

    Default Re: About QScroll Area

    Sorry but nothing is exploding in my face and yes I run your example.
    I think you should speak in a different way as administrator without ridicole the work of other developers.
    Maybe I'm not a Qt expert, my field is another and if I ask for help here is to learn and improve my Qt.

    Best Regards
    Franco Amato

  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: About QScroll Area

    Quote Originally Posted by franco.amato View Post
    Sorry but nothing is exploding in my face
    If things that are working for me are not working for you then the only thing to blame is the code already in your application.
    and yes I run your example.
    Did it work? Did you adapt it to your application? Did it work there?

    I think you should speak in a different way as administrator without ridicole the work of other developers.
    This forum is here mainly to help others and not to praise their work, be it good or bad.

    Maybe I'm not a Qt expert, my field is another and if I ask for help here is to learn and improve my Qt.
    So learn and improve instead of going forward the wrong path even if someone is constrantly trying to pull you away from it.

    You can abuse some mechanisms in Qt and they will work. But at some point you reach a situation when the side effects of all the abuses get stacked and accumulate effectively preventing you from finishing your task successfully. The rules of Software Engineering say that the latter you spot the problem, withdraw from it and do things the proper way, the more expensive it is.
    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.


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

    Default Re: About QScroll Area

    Quote Originally Posted by wysota View Post
    If things that are working for me are not working for you then the only thing to blame is the code already in your application.
    I didn't say that it doesn't work, I said that I don't need it also if your example is very good. Maybe my english sometime is not perfect.

    Did it work? Did you adapt it to your application? Did it work there?
    Yes it works. In the attached widget I already have a timer that move a timeline so the routine used by me seems perfect for my purpose.
    Johan Thelin suggested it to me.


    This forum is here mainly to help others and not to praise their work, be it good or bad.


    So learn and improve instead of going forward the wrong path even if someone is constrantly trying to pull you away from it.

    You can abuse some mechanisms in Qt and they will work. But at some point you reach a situation when the side effects of all the abuses get stacked and accumulate effectively preventing you from finishing your task successfully. The rules of Software Engineering say that the latter you spot the problem, withdraw from it and do things the proper way, the more expensive it is.
    If this routine is so bad, why it exists? Seems done for my purpose
    Franco Amato

  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: About QScroll Area

    Quote Originally Posted by franco.amato View Post
    Yes it works. In the attached widget I already have a timer that move a timeline so the routine used by me seems perfect for my purpose.
    I don't see how using ensureVisible() is more "perfect" than setting the value of the scroll bar to 0 but have it your way...

    If this routine is so bad, why it exists? Seems done for my purpose
    "If division by 0 is a bad thing then why does division exist at all?"

    In other words, I didn't say the routine is bad, I said it's bad in your case (actually it's not that bad in this situation but once you start adding more functionality it might become bad).
    Last edited by wysota; 26th January 2010 at 17:06.
    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.


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

    Default Re: About QScroll Area

    Quote Originally Posted by wysota View Post
    I don't see how using ensureVisible() is more "perfect" than setting the value of the scroll bar to 0 but have it your way....
    Why should I set the value to zero? I have to keep visible the timeline ( in my case a moving line from left to right ) that disappear in the right size of the widget when I resize it ( while playing a sound )


    "If division by 0 is a bad thing then why does division exist at all?"

    In other words, I didn't say the routine is bad, I said it's bad in your case (actually it's not that bad in this situation but once you start adding more functionality it might become bad)
    I think you didn't understand my scenario, sure for my bad english sorry.

    Best Regards
    Franco Amato

  16. #16
    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: About QScroll Area

    Quote Originally Posted by franco.amato View Post
    Why should I set the value to zero? I have to keep visible the timeline ( in my case a moving line from left to right ) that disappear in the right size of the widget when I resize it ( while playing a sound )
    Well, you said "shifted to the left". I understood you want to go back to the beginning when the timeline ends.
    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.


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

    Default Re: About QScroll Area

    Quote Originally Posted by wysota View Post
    Well, you said "shifted to the left". I understood you want to go back to the beginning when the timeline ends.
    Sorry my bad english plays against me
    Franco Amato

Similar Threads

  1. About visual area
    By calmspeaker in forum Qt Programming
    Replies: 0
    Last Post: 16th March 2009, 13:14
  2. Replies: 19
    Last Post: 26th November 2008, 19:54
  3. Qt From Without Title area
    By nleverin in forum Newbie
    Replies: 3
    Last Post: 7th March 2008, 06:45
  4. scroll area like QGraphicsItem
    By Gopala Krishna in forum Qt Programming
    Replies: 1
    Last Post: 7th February 2008, 11:28
  5. select a particular area
    By vishesh in forum Qt Programming
    Replies: 4
    Last Post: 28th February 2007, 21:44

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.