How to prevent QScroller gesture from interfering with QGraphicsView drag mode? - c++

I am developing a touchscreen compatible app that has some widgets that contain QScrollAreas. I am using
QScroller::grabGesture(ui->scrollArea->viewport(), QScroller::LeftMouseButtonGesture);
to allow the user to easily scroll these widgets by swiping.
However, some of the scroll areas contain subclassed QGraphicsViews. I am adding QGraphicsItems to these and would like the user to be able to select items using rubberbanding. I have set the drag mode using
setDragMode(QGraphicsView::RubberBandDrag).
This works as desired if I don't also use grabGesture on the scroll area containing the view.
However, grabbing the gesture for the swipe scrolling interferes with the rubberbanding action of the graphics view.
How can I scroll widgets containing these views while also keeping the rubberbanding functionality in tact? I essentially want the widget to scroll unless the user is swiping inside of a QGraphicsView.

Related

Is there a way to attach or anchor two QWidgets together?

I'm getting started with Qt and decided to build a full-screen text editor. I want to have a button (button with arrow in screenshot) attached to a QDockWidget which opens and closes it so the button is always visible to the right side of the screen and stay anchored to it when dock is visible or resized.
My current app is a simple fullscreen textEdit set to centeralwidget in Mainwindow.
I haven't found a way to do this yet with layouts or existing addAnchor() functions so any help or direction is appreciated.
You can achieve what you want by using a container for your text edit and the button. A QWidget instance can be used as an "invisible"*** container for other widgets.
So in Qt Designer you add a widget as a central widget of the main-window, inside this widget you add the text edit and the button, then you set a vertical layout for this container widget.
Don't forget to restrict the docking widget to only dock to the right side, you can do that with: dock->setAllowedAreas(Qt::DockWidgetArea::RightDockWidgetArea); //assuming dock is the pointer to your QDockWidget.
In case you want the dockWidget to be able to dock to any side and the button to follow, you can do that too, but it get a little bit more complicated. Basically you need to connect a slot to dockLocationChanged of your dockWidget and based on where it's docked you need to set-up a new layout for the container widget to be vertical or horizontal and the order of the textEdit and the button based on the side the dock happened.
LE:*** you will most likely need to set the margins you want, since both the widget and it's layout can have them and the actual content might have higher spacing than you want.

Expandable list view with customized scrollbar in Qt

I want to build a widget like this one that we can find in Word :
So, there is a list view using a specific scrollbar with 3 buttons and no scroll.
When you click on the last button at the bottom right, a new list view with a classic scrollbar is shown over the previous list view (hidden when losing focus). So basically, the smae behavior as the one in Word.
We are already capable of displaying a list view with custom content.
My main concern is how to build the widget in the first image: the list view with the custom scrollbar (3 buttons, no scroll)?
What is the proper way to do this ?
I assume that you're implementing a subclass of QAbstractListView.
I don't believe you need a custom scrollbar - just put the scrollbar and the button into a QVBoxLayout; hide the button once it's checked (you could even connect its toggled() to its setHidden() for that).
At first hide the default scroll-bar by calling the QAbstractScrollArea::setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) method.
Then create your three buttons on the left side and connect the QPushButton::clicked() signals to some slots where you just scroll your list by calling the QAbstractItemView::scrollTo(index), QAbstractItemView::scrollToBottom() or QAbstractItemView::scrollToTop().
While it is correct that you could just build a custom widget consisting of a view with hidden scrollbars and add the buttons to the layout, connecting the signals/slots needed to provide the proper actions, you can also consider to implement your own QScrollBar class. QListView is derived from QAbstractScrollArea, which provides setVerticalScrollBar() so you can just set an object of it to be used by the view. The integration of scroll area and scroll bar should be much more straightforward this way, but you'll have to do the painting of the scroll bar's content yourself, or put a layout and the buttons in there (QScrollBar derives from QWidget, and you'll have to reimplement paintEvent()).

Allow user to resize widgets at runtime in QT5

I have an application written in C++/QT5 with a QListView widget within a QHBoxLayout within a QGroupBox. There is also a QTabWidget in the main window. I would like the user to be able to resize the QListView widget by clicking and dragging and for the other items to automatically resize themselves accordingly.
I feel like this should be something that is easily done within the framework of QT5, but I can't for the life of me find a way. Even having a border on the list view that I can resize within the code of my application would be a start.
Thanks to jhnnslschnr I was able to solve this via the QSplitter widget. If you're using QtCreator as I was, you can use QSplitter simply by Ctrl-clicking the widgets you want in the splitter and then selecting "Lay out horizontally (vertically) in splitter". The user can now select the partitioning at run-time.

scrollbars of a CScrollView in a CDockablePane are disabled

I've designed a toolbox control. It's inside a CDockablePane object. Since the tools inside it may need to be scrolled, I've created a CScrollView as a child of the pane and have inserted the tools inside it as children. Based on the pane size, scrollbars of the CScrollView object appear properly, but clicking on them doesn't scroll the view. It seems that they're disabled. When I use SS_NOTIFY style when creating the CScrollView, the CScrollView object receives mouse clicks, but when i don't use the style, it doesn't. But it seems that the scroll bars inside the view control don't receive clicks. When mouse hover over them, no visual effect in scroll bars appears. It seems that the scroll bars are disabled, while I've not created nor manipulate them.
What's wrong?
mouse wheel works. click on scrollbars is received by the scroll view, not by the scrollbars. inside handler, i wrote this code:
CScrollBar *pScroll = GetScrollBarCtrl(SB_VERT);
if (pScroll->GetSafeHwnd())
{
...
if is not true. this means that the scroll view has not a scroll bar, but if so, how is it shown?!
any idea?
...
since i didn't get answer, i'm going to clarify my question with a sample code:
https://dl.dropboxusercontent.com/u/4829119/930501%20-%20t3.zip
in this sample, how can i scroll my view as i do with other views like class view and file view?
the sample code screenshot:
https://www.dropbox.com/s/7pu5chpyj9hqeal/Screenshot%202014-07-23%2003.40.26.png
Did you initialize by calling SetScrollSizes? The scroll bars are enabled only when the sizeTotal is larger than the view window size.

Implementation of gui designer

I'm interested in making my own small gui designer for learning purposes in Qt. Just basic drag and drop from left panel which would have controls, to right panel on which they could be selected, moved, resized and have their properties changed (name and such) and eventually (if selected) be lined up.
I would use QGraphicsScene as the right panel cause it already has selecting and moving implemented. But how would I implement resizing? And then how would I generate a QWidget class with controls at same positions? Or is there an easier way?
What would be the best way to implement all of this? All suggestions are welcome and keep in mind that it won't be complex as Qt designer.
You need to define some widgets, which are going to be dragged from the left panel -maybe a tree view with icons- and dropped to the scene.
These widgets should inherit from QGraphicsWidget. You can also inherit QWidget and put the widgets into scene via QGraphicsProxyWidget. They can be resized by highlighting corners and overloading the mouse events. Please check out corner grabbers and sizable box examples. Also check out QSizeGrip. It is the resizing grip of any QStatusBar.
Property panel is the easiest, you should list the properties of the clicked item. To line up, you can reinvent the wheel and write a layout maker class, or simply use QGraphicsLayout and highlight the layout on your interface. Ctrl+left click should select multiple widgets, a layout button should layout them programmatically, and a bounding rectangle item should be drawn.