PDA

View Full Version : Tableview with grabGesture but it's slider should work with non-grabGesture logic



omnio2006
4th February 2021, 10:52
My goal is to have a Tableview that has 2 specific things:

Thing #1:

1.1 Left mouse button UP behaviour:
When I press with the left mouse button and hold it on the view with rows and columns and move the mouse UP
=> I want to see the "QScroller::grabGesture" behaviour, it means that - the table moves down,
and the slider on the scrollbar also moves down, while the mouse coursor with the pressed left button moves UP.

1.2 Left mouse button DOWN behaviour:
When I press with the left mouse button and hold it on the view with rows and columns and move the mouse DOWN
=> I want to see the "QScroller::grabGesture" behaviour, it means that - the table moves up,
and the slider on the scrollbar also moves up, while the mouse coursor with the pressed left button moves DOWN.

Thing #2:

When I press with the left mouse button and hold it on the SLIDER and move the mouse up or down
=> I want to turn the "QScroller::grabGesture" behaviour OFF, and use the slider in his "default" mode, - if I move the slider down then the table moves down and if I move the slider up then the table moves up.

------------------------
In my sample project QtWgtScrollerTestApp I achieve that. But I came across some problems:

#1 Problem:
I need to wait some time (around 200 or 400 milliseconds) after I press on the Slider for the signal QScrollBar::sliderPressed to be emited.
If I start to move the mouse at the same time when I press on the slider, sliderMoved signal emits earlier and sliderPressed seems not to be emited at all after that.

#2 Problem:
When I start my app, and right away CLICK (press and release) with the left mouse button on the slider I am getting a "Segmentation fault" somewhere in a qmap source code



const QMapNodeBase *QMapNodeBase::nextNode() const
{
const QMapNodeBase *n = this;
if (n->right) {
n = n->right;
while (n->left) // <- "Segmentation fault" line
n = n->left;
} else {




QUESTION:
What is the correct way to achieve the behavior for a tableview and the slider that I want and have discribed above (with Thing #1 + Thing #2) ?
If my sample project is generally correct, how do I get ridd of the 2 problems described above ?
Or at least how to avoid the "Segmentation fault" problem in my project ?

d_stranz
4th February 2021, 16:29
#1 Problem:
I need to wait some time (around 200 or 400 milliseconds) after I press on the Slider for the signal QScrollBar::sliderPressed to be emited.

This is probably something built into Qt so it can distinguish between a press and a move. There is probably a timer started when the mouse button goes down, and if a mouse move is detected before the timer fires, then the sliderMoved signal is sent. If there is no movement and the timer fires, then the pressed signal is sent.

To achieve what you want, you will probably have to derive from QScrollBar and re-implement the mousePressEvent() and mouseMoveEvent() methods. You can set a new scrollbar on your table view via QAbstractScrollArea::setVerticalScrollBar().


#2 Problem:
When I start my app, and right away CLICK (press and release) with the left mouse button on the slider I am getting a "Segmentation fault" somewhere in a qmap source code

Probably that has nothing to do with the real error - it just happens to show up there because memory got corrupted before it got to that point and that's where pointers go off into limbo.

My guess is that you probably have a pointer variable somewhere that you are using before it is initialized, or your code has walked off the end of an array either in reading or writing.