PDA

View Full Version : [SOLVED] QDeclarativeView mousearea and mouseEvents problems.



acidr
16th July 2011, 12:05
Hi all! :D

I photoshopped a custom user interface for a application i want to bring to life someday primarily for the windows platform. It has a custom titlebar with custom buttons and i designed tree-state windows actions buttons for closing, minimizing and maximazing.

First off: would you advice against using QML for this, or is that exactly what QML could be used for?

The problem I'm striving with is mouse-events. I must have done something wrong because when I implement my QML-file (witch work as expected in the qmlviewer) in the QDecalarativeView it doesn't handle mouse-events at all (no hover, click, or anything realy).
I also would preferably need the mouseevents that arent handled in my qml-file to propagate eighter to a subclassed QDeclarativeView (in c++) or all the way up to my QMainWindow::mousePressEvent(..). So that I can implement moving the window and resizing it.

Has anybody got any ideas for me? I'll be happy to look myself, I'm just kinda stuck right now. A point in the right direction would go a long way :D

Thanks!

EDIT:

Okay so I ended up sub-classing the QDeclarativeView and using its mouseEvent functions (also calling QDecalarativeView::mouseXEvent(event); every time to have the qml work aswell) to implement moving and resizing functionality.

Then I used a normal QWidget sub-classed class to set the titlebar together with the rest of the content and complete the custom window.

Thanks for the help viulskiez.

viulskiez
16th July 2011, 13:02
I photoshopped a custom user interface for a application i want to bring to life someday primarily for the windows platform. It has a custom titlebar with custom buttons and i designed tree-state windows actions buttons for closing, minimizing and maximazing.

First off: would you advice against using QML for this, or is that exactly what QML could be used for?

I also would preferably need the mouseevents that arent handled in my qml-file to propagate eighter to a subclassed QDeclarativeView (in c++) or all the way up to my QMainWindow::mousePressEvent(..). So that I can implement moving the window and resizing it.


So you need a custom user interface and the main window must at least movable, resizeable, can be minimized, maximized and closed? I suggest to subclass Qwidget for this purpose then reimplement paintEvent, mousePressEvent, mouseReleaseEvent and mouseMoveEvent. And when you really need QDeclarativeView, you can put it inside the custom widget. It's mean I use composition, not inheritance... But you can also inherit your custom widget from QDeclarativeView like in QmlApplicationViewer.

acidr
16th July 2011, 13:39
Thanks for the answer. I am already able to show a window almost as I want it to look. I have a vertical grid with the qdeclarativeview being the titlebar and next theres a horizontal grid that contains the rest of my widgets.

You might be right that it would be better to reimplement it in a fresh qwidget. But I just don't understand why I cant record any mouseEvents. (even though I can see the titlebar it's non-responsive and dead)

Added after 9 minutes:

Okey so I tried just running my QML in a QDeclarativeView alone, that worked fine. I'll try something more substantial (sub-classing it and using it as my main window).
Thanks