Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QScroller::LeftMouseButtonGesture on multiple scroll areas
Forum Updated to NodeBB v4.3 + New Features

QScroller::LeftMouseButtonGesture on multiple scroll areas

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 4 Posters 865 Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DaveK 0
    wrote on last edited by
    #1

    I have multiple stacked pages in a stacked widget. Several of those pages have QScrollAreas on them.

    I would like each of the scroll areas to allow the user to scroll left/right in the area with a touch or leftclick gesture. Below I try setting the LeftMouseButtonGesture on each of the scrollAreas, depending on the page that is at the top of the stack (visible).

    But i'm getting some very strange behavior that is hard to describe. When I first start my application, the LeftMouseButtonGesture works to scroll horizontally on both pages, but after I switch back and fourth between the two pages, it always stops working on the second of the two while continuing to work on the first.

    Is there a better way to achieve this, or something I should be doing differently? I've tried both of the following ways:

    Method 1 - on each page change of the stacked widget:

    void MainWindow::on_stackedWidget_currentChanged(int pageNum)
    {
    	switch(pageNum)
    	{
    	case Pages::pg_1:
    		QScroller::grabGesture(ui->scrollArea_Page1, QScroller::LeftMouseButtonGesture);
    		break;
    
    	case Pages::pg_2
    		QScroller::grabGesture(ui->scrollArea_Page2 QScroller::LeftMouseButtonGesture);
    		break;
    
    	//More page cases will go here.
    	
    	}
    }
    

    Method 2 - Set all gestures in my MainWindow Init.

    MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
    	ui(new Ui::MainWindow),
    {
        ui->setupUi(this);
    
        QScroller::grabGesture(ui->scrollArea_Page1, QScroller::LeftMouseButtonGesture);
        QScroller::grabGesture(ui->scrollArea_Page2 QScroller::LeftMouseButtonGesture);
    }
    

    Both methods seem to produce the same result where one of the two pages stops scrolling via the gesture (both are always scroll-able via the scroll bar at the bottom).

    M 1 Reply Last reply
    1
    • D DaveK 0

      I have multiple stacked pages in a stacked widget. Several of those pages have QScrollAreas on them.

      I would like each of the scroll areas to allow the user to scroll left/right in the area with a touch or leftclick gesture. Below I try setting the LeftMouseButtonGesture on each of the scrollAreas, depending on the page that is at the top of the stack (visible).

      But i'm getting some very strange behavior that is hard to describe. When I first start my application, the LeftMouseButtonGesture works to scroll horizontally on both pages, but after I switch back and fourth between the two pages, it always stops working on the second of the two while continuing to work on the first.

      Is there a better way to achieve this, or something I should be doing differently? I've tried both of the following ways:

      Method 1 - on each page change of the stacked widget:

      void MainWindow::on_stackedWidget_currentChanged(int pageNum)
      {
      	switch(pageNum)
      	{
      	case Pages::pg_1:
      		QScroller::grabGesture(ui->scrollArea_Page1, QScroller::LeftMouseButtonGesture);
      		break;
      
      	case Pages::pg_2
      		QScroller::grabGesture(ui->scrollArea_Page2 QScroller::LeftMouseButtonGesture);
      		break;
      
      	//More page cases will go here.
      	
      	}
      }
      

      Method 2 - Set all gestures in my MainWindow Init.

      MainWindow::MainWindow(QWidget *parent) :
          QMainWindow(parent),
      	ui(new Ui::MainWindow),
      {
          ui->setupUi(this);
      
          QScroller::grabGesture(ui->scrollArea_Page1, QScroller::LeftMouseButtonGesture);
          QScroller::grabGesture(ui->scrollArea_Page2 QScroller::LeftMouseButtonGesture);
      }
      

      Both methods seem to produce the same result where one of the two pages stops scrolling via the gesture (both are always scroll-able via the scroll bar at the bottom).

      M Offline
      M Offline
      m_vantaggi
      wrote on last edited by
      #2

      @DaveK-0 I have the same problem.

      Ramkumar MohanR 1 Reply Last reply
      0
      • mrjjM Offline
        mrjjM Offline
        mrjj
        Lifetime Qt Champion
        wrote on last edited by
        #3

        Hi
        It seems to be related to being inside a QStackedWidget.
        It works as expected if the QScrollAreas are just next to each other.
        However, if you put them in stacked. It stop working.

        The docs states
        "Note: To avoid unwanted side-effects, mouse events are consumed while the gesture is triggered. Since the initial mouse press event is not consumed, the gesture sends a fake mouse release event "
        and i think its related to this. but i dont know how/why.

        1 Reply Last reply
        0
        • M m_vantaggi

          @DaveK-0 I have the same problem.

          Ramkumar MohanR Offline
          Ramkumar MohanR Offline
          Ramkumar Mohan
          wrote on last edited by
          #4
          This post is deleted!
          1 Reply Last reply
          0

          • Login

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • Users
          • Groups
          • Search
          • Get Qt Extensions
          • Unsolved