Page 2 of 2 FirstFirst 12
Results 21 to 24 of 24

Thread: mouse wheel event and QListWidget: wrong behaviour?

  1. #21
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: mouse wheel event and QListWidget: wrong behaviour?

    You should even be able to directly connect each scrollbar's valueChanged() signal to the other two scrollbar's setValue slot.
    No, I think I tried this once. If you have a circular loop of connections from one list to the next and then back to the first, I am pretty sure this sets up a recursion. setValue() causes valueChanged() to be emitted.

    I do not know if the sanity check in my slot is performed internally by the scroll bar, but if it is, then the recursion might not occur and you can directly connect the scrollbars' signals and slots. I will leave that as an exercise for the OP to investigate.

  2. #22
    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: mouse wheel event and QListWidget: wrong behaviour?

    Quote Originally Posted by d_stranz View Post
    setValue() causes valueChanged() to be emitted.
    setValue() should only trigger valueChanged() if the value changes.
    If the two scrollbars have the same range, a change of one value can be exactly mapped to the other.
    The signal back would then not change anything, thus not lead to valueChanged() being emitted yet again.

    Works for QSlider, which is another implementation of QAbstractSlider.
    (very common to connect a slider to a spinbox and vice versa for both type and slide input)

    Cheers,
    _

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

    d_stranz (7th January 2015)

  4. #23
    Join Date
    Jul 2014
    Posts
    32
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: mouse wheel event and QListWidget: wrong behaviour?

    Thanks guys, It is working now without a hack. And so easy to implement.

  5. #24
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,321
    Thanks
    316
    Thanked 871 Times in 858 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: mouse wheel event and QListWidget: wrong behaviour?

    setValue() should only trigger valueChanged() if the value changes.
    If the two scrollbars have the same range, a change of one value can be exactly mapped to the other.
    The signal back would then not change anything, thus not lead to valueChanged() being emitted yet again.
    OK, then, if that's the case I can update my code to this:

    Qt Code:
    1. MainWindow::MainWindow( QWidget * parent )
    2. {
    3. // ... setupUI() , etc.
    4.  
    5. QScrollBar * listScroll1 = list1->verticalScrollBar();
    6. QScrollBar * listScroll2 = list2->verticalScrollBar();
    7. QScrollBar * listScroll3 = list3->verticalScrollBar();
    8.  
    9. connect( listScroll1, SIGNAL( valueChanged( int ) ), listScroll2, SLOT( setValue( int ) ) );
    10. connect( listScroll1, SIGNAL( valueChanged( int ) ), listScroll3, SLOT( setValue( int ) ) );
    11.  
    12. connect( listScroll2, SIGNAL( valueChanged( int ) ), listScroll1, SLOT( setValue( int ) ) );
    13. connect( listScroll2, SIGNAL( valueChanged( int ) ), listScroll3, SLOT( setValue( int ) ) );
    14.  
    15. connect( listScroll3, SIGNAL( valueChanged( int ) ), listScroll1, SLOT( setValue( int ) ) );
    16. connect( listScroll3, SIGNAL( valueChanged( int ) ), listScroll2, SLOT( setValue( int ) ) );
    17. }
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. Scrolling on Mouse Wheel
    By penny in forum Qt Programming
    Replies: 4
    Last Post: 7th April 2011, 07:30
  2. QGLWidget and wheel event
    By shenakan in forum Qt Programming
    Replies: 1
    Last Post: 6th November 2009, 15:21
  3. wheel event problem
    By bhogasena in forum Qt Programming
    Replies: 1
    Last Post: 30th January 2009, 19:11
  4. Handling mouse over event for QListWidget
    By Abc in forum Qt Programming
    Replies: 2
    Last Post: 22nd July 2008, 18:32
  5. how to send a emulated mouse event to QListWidget
    By yxmaomao in forum Qt Programming
    Replies: 4
    Last Post: 22nd July 2008, 02:49

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.