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. disable horizontal scrolling in qTableWidget
Forum Updated to NodeBB v4.3 + New Features

disable horizontal scrolling in qTableWidget

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 2.1k Views
  • 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.
  • Y Offline
    Y Offline
    Yina
    wrote on last edited by
    #1

    Hello,

    I am trying to make an app for touch screen devices but I have a qTablewidget where you can scroll because the widget is bigger then the screen you need horizontal scrolling, but the horizontal scrolling makes it annoying for the user to see the most important data (on the left) because sometimes you scroll accidentally to the right when scrolling vertically.
    So my question is how to disable horizontal scrolling with the finger/wheel but it should be possible with the scroll bar?

    kind regards
    Yina

    1 Reply Last reply
    0
    • JoeCFDJ Offline
      JoeCFDJ Offline
      JoeCFD
      wrote on last edited by JoeCFD
      #2
      m_tableWidget->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
      

      also try if the code above does not help
      m_tableWidget->horizontalHeader()->setSectionResizeMode( QHeaderView::Fixed );
      m_tableWidget->horizontalHeader()->setStretchLastSection( true );

      Y 1 Reply Last reply
      0
      • JoeCFDJ JoeCFD
        m_tableWidget->setHorizontalScrollBarPolicy( Qt::ScrollBarAlwaysOff );
        

        also try if the code above does not help
        m_tableWidget->horizontalHeader()->setSectionResizeMode( QHeaderView::Fixed );
        m_tableWidget->horizontalHeader()->setStretchLastSection( true );

        Y Offline
        Y Offline
        Yina
        wrote on last edited by
        #3

        @JoeCFD

        The issue is that the width of the table is bigger than the width of the screen but if you scroll down it is quite easy to be accidentally on the right side of the table(because you scroll to the right) and then the user can't see the most important data on the left side of the table. that is why I want to disable horizontal scrolling but it should still be possible with the scrollbar to scroll horizontally.

        kind regards
        Yina

        JonBJ 1 Reply Last reply
        0
        • Y Yina

          @JoeCFD

          The issue is that the width of the table is bigger than the width of the screen but if you scroll down it is quite easy to be accidentally on the right side of the table(because you scroll to the right) and then the user can't see the most important data on the left side of the table. that is why I want to disable horizontal scrolling but it should still be possible with the scrollbar to scroll horizontally.

          kind regards
          Yina

          JonBJ Offline
          JonBJ Offline
          JonB
          wrote on last edited by
          #4

          @Yina
          If there isn't anything "inbuilt" to make a scrollbar respond to clicks but not wheel, and nothing to switch wheel off, I would have thought you'd want to look at getting at the low-level wheel events and ignoring them? Would an eventFilter() let you distinguish between these inputs so you can filter out the wheel?

          1 Reply Last reply
          0
          • JoeCFDJ Offline
            JoeCFDJ Offline
            JoeCFD
            wrote on last edited by JoeCFD
            #5

            As JonB said, disable horizontal scrolling in vertical scrolling event
            and enable it when it is done.

            On touch screen, you check mouse press event
            disable
            mouse release event
            enable

            or check the following code

            bool TouchResetApplication::notify(QObject *receiver, QEvent *event)
            {
                switch (event->type()) {
                case QEvent::TouchBegin:
                case QEvent::TouchUpdate:
                case QEvent::TouchEnd:
                case QEvent::TouchCancel:
                    return true;
                default:
                    return QApplication::notify(receiver, event);
                }
            }
            
            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