Panning QScrollArea with a mouse - qt

I have a QScrollArea. I would like to make the context pannable with a mouse - such that, a hand cursor is shown over the area and click-and-hold gets us into dragging mode.
This would be similar to what QGraphicsView can do easily with QGraphicsView::ScrollHandDrag dragging mode, only that I need it for QScrollArea.
Any idea on how to have it out of the box? Or perhaps a piece of code to do it manually? I am certainly not the first one who wants it..

Should not be difficult, especially using event filter. Take a look at my old blog post on Flick list or kinetic scrolling (the code has been moved to http://qt.gitorious.org/qt-labs/graphics-dojo). As a bonus, you can get the momentum effect easily!

Okay. At the end I changed it to QGraphicsView and it was easy to do, worked great out of the box.

Related

Google VR Reticle Click on UI Button

So I am having this issue with using Google VR reticle where I cannot click a button. I have an image attached showing the heirarchy and the PlayButton is what I am trying to click. The Canvas has a Graphic Raycaster, the button has an Event Trigger that calls the method to navigate to the next scene. The UpScrollPanel, and DownScrollPanel work just fine. The EventSystem has the Gaze Input Module, as well as Event System, and Touch Input Module.
Any ideas on how to get this working? I have watched a few videos from NurFACEGAMES and while they helped a little, I haven't gotten the click to work yet.
Oh, and I am using Unity 5.3.4f
Sometimes things can get in the way of the button, make sure that no other UI elements overlap it, for example text borders (which are actually larger than they appear). You can also fix this by moving the button up the hierarchy among its siblings, I believe the first child is top.
Also try moving the button up the hierarchy if possible, sometimes UI having certain parents makes them not work
The canvas object should have a graphic raycaster
I found the issue to be unrelated to anything I thought it was. The menu I was using is a prefab I also use in another view that isn't VR. The scrollrect was loading that prefab, instead of the modified one I was using in the VR menu, and therefore the triggers I had added to the button were no being used when the app loaded.

how to get a "lightbox" like behaviour in Qt

I have a Qt project where I'm using QGraphicsView framework, also I have popup windows on the scenes. (QDialogs)
When someone clicks on a certain button a popup window appears, and I'm invoking it with the .exec() method instead of .show() to make it the active one. Also I want to give it a visual effect like lightbox provides for html pages, so it would be obvious for the user too, that the background window won't communicate. Do you know any simple solution to make it work? or is it hard to implement in Qt?
EDIT: I don't know if it's obvious of not, but it's a desktop application, not a web application.
Just create QFrame over necessary area with customized background and transparency. For animation effect you may use QPropertyAnimation + QGraphicEffects and other stuff from qt animation framework.
Now I found another way to accomplish what I wanted. Like this:
QWidget* mytranswidget = new QWidget(mybgwidget);
mytranswidget->setStyleSheet( "background:transparent; background-color:rgba(0,0,0‌​,95)");
mytranswidget->setWindowFlag(Qt::FramelessWindowHint);
mytranswidget->setGeometry(mybgwidget->rect());
mytranswidget->show();
I'm doing it at the beginning of my popup widget's constructor so it's being drawn before draw my popup, so it will be shown in the right order.

Showing when a button has been pushed in Qt

I'm using Qt with C++, and I want to make a button that keeps looking pushed down after it is pushed and released. I'm currently making buttons on a QToolBar and doing something like toolBar->addAction (icon, tr("Text"));. This makes buttons on the toolbar that display the QIcon named icon and display "Text" on hover-over. They also look pushed down as the user is pushing them, but stop looking pushed down when they are released (as is reasonable for most uses of buttons). I need something different, however: I would simply like the buttons to remain looking pushed down after they are released, perhaps until they are clicked again. It would be best if I could just call some function on a button or on the toolbar that could give me the capacity to control whether a button will look pushed down or not pushed down when it is displayed. That way I could just control this aspect of button appearance programmatically.
What's the easiest way to do this in Qt? I've seen fancy ways of doing it involving borders and very complicated setups, but I was wondering whether there might be an easy way to do it.
Add QPushButton to the toolbar using addWidget and then make the button checkable.

Flex detect when mouse leaves a Canvas

I am trying to detect when the mouse leaves a canvas. I know about the MOUSE_LEAVE, but this seems to only be valid for the stage, not Canvas objects.
take care,
lee
P.S. I have tried the mous-out, but, for some reason, that event keeps getting triggered everytime I move the mouse.
I should probably point out that I have used the Mouse.hide() and replaced the cursor with a custom cursor.
You could use either the MouseEvent.ROLL_OUT event or MouseEvent.MOUSE_OUT.
To see what is the difference and what you should use, read this article.
Try to use mouseOut event.
Thanks everyone. The trick was to set the custom cursor's parent to mouseChildren = false. Not a practical solution for most situations, but good for this.
The problem was coming from the fact that the mouse is still on the stage and moves slightly faster than the code move the custom mouse. So if the mouse was moved too quickly, it actually moved off the custom cursor.
take care,
lee

Qt - In QGraphicsScene how to put a picture dynamically

Hai,
I am trying to create a chess board. Here I want to do a operation like when ever a coin is clicked and dragged, at that time that picture should be copied and be placed in that old position. I don't know in which function I have to do it. When I made it on mouse pressed, then tyhe copy is coming above the original(layer wise). So somebody please help me
When I made it on mouse pressed, then tyhe copy is coming above the original(layer wise).
When you got this far, simply adding a call to myItemCopy->setZValue( -1 ) would place the copy "behind" the original item.
A different approach, and possibly "cleaner", would be to use QDrag and tell Qt how to paint your item during the Drag operation. See Qt's "Drag and Drop Robot" example for reference: http://doc.qt.io/qt-5/qtwidgets-graphicsview-dragdroprobot-example.html
Happy coding!
Robin
Simplest way to do this will be to put 2 identical QGraphicsItems for each coin/piece at the same location. The top one will be dragged and moved while the bottom one will stay for the visual cue you want.
Once the top one is dropped to the new location, move the bottom one there too.

Resources