I am developing a application with Qt.
I have a push button and I'm using signal/slot for setting a different text.
The problem is that I want to use it with touch screen. I have the coordinates when I touch the screen.
So far I can change the text by pressing on the touch screen (any coordinate) but I don't know how to do it only when I push the button.
If you have any ideas I would appreciate it.
Thanks
Touch events are commonly handled just like mouse clicks (it depends on the Qt driver you're using but it commonly is handled that way). So use the pressed() signal as usual.
Related
I made a small video app with fullscreen support. While the video is playing I can push a button in my video controller and the app changes to fullscreen.
The strength thing is, when I'm in fullscreen the button has still somehow the focus in this way that when I move over it , it thinks I pushed (also the hover of the button is active even when I'm not over it with the mouse)
This behaviour end then up in a endless with to and from fullscreen when I'm not moving the mouse after pushing the button
I had here a similar problem in Qt4, but here the mouse over was only active after pushing
so perhaps somebody has an idea what's happening here, could not find anything in the Qt buglists
Georg
I don't know if it is a bug or an intended behaviour, nevertheless you may try to solve this problem in several ways. In the slot called whenever you change the size of the window, call one or several of the following QPushButton methods:
clearFocus() - that should make the button stop receiving keyboard/mouse input;
releaseKeyboard() and releaseMouse() should effectively do the same;
If you don't need the button while in fullscreen, you can also simply make it stop receiving any user input at all:
disable it (setEnabled(false));
make it invisible (invisible widgets don't receive keyboard/mouse input) by calling setVisible(false);
disconnect() the button and thus make it stop receiving any signals, and connect() it again after turning the fullscreen mode off.
I'm writing a Qt application which uses mpv for playing different videos.
QWidget is used to show video content. I also have custom dock with controls for switching video channels, changing position, etc.
I want to have dock appearing after a click on the screen and disappearing on timer event. It all works fine, except from the fact, that QWidget used for mpv is not receiving QMouseEvent. On the contrast same event works fine for main window. Basically dock appears only if you click on visible part of main window and not on mpv Qwidget.
I assume it is because mpv has internal support for keybindings. I've tried to disable them by setting "input-default-bindings" to "no", but it didn't help.
mpv_set_option_string(mpv, "input-default-bindings", "no");
Can anybody help with that?
Does anybody know how to configure keybindings for mpv (I can't find any example in documentation)?
Maybe there is a workaround for it?
Thanks a lot.
You can use a transparent widget in front of video area to receive and redirect QMouseEvent to your custom dock. Though this is not a beautiful solution... How to create such widget is described here.
My application has a big graphics area with some controls (sliders, buttons, text edit controls) in a side panel. The graphics area understands some keyboard commands.
My problem is that when a control in the side panel is in focus, the main graphics area won't receive any keyboard commands, so this confuses the users. However, for some controls, this is intended, e.g. text edit controls.
What I want is the focus to automatically return to the graphics area at the earliest possible occasion (which I call "greedy" focus) -- e.g. when text editing is finished (Enter key), or when the user has selected an item from a combo box.
I am looking for a clean and robust strategy for dealing with the problem, either using Windows API or Borland Vcl.
I'd appreciate if you want to share your ideas.
I haven't fully solved the problem yet, but a very useful message to intercept on form level is CM_DIALOGKEY (Borland Vcl only). It gets sent for every key that is normally used for navigating within the UI. That is, cursor keys, tab and shift-tab, Enter and possibly others.
I've added an event handler for CM_DIALOGKEY that returns the focus to the graphics area and also forwards the key press to that component. This way the user can still control the UI elements via keyboard (important for text entry), but cursor keys are handled by the graphics area.
I know what you mean I had similar problem with some BIG apps lice CAD/CAM ...
My solution is simple, robust and I use it for years.
1.all keystrokes handling for that gfx area
must be done in events of the Form where the area is located
not in panels,paint box whatever...
2.create unfocus function (preferably member of form but it is not required)
this function will loose focus of any VCL item
so the focus goes to form itself which is what you want
I am using this:
//---------------------------------------------------------------------------
void main_unfocus()
{
Main->bt_unfocus->Visible=true;
Main->bt_unfocus->SetFocus();
Main->bt_unfocus->Visible=false;
}
//---------------------------------------------------------------------------
Main is the Form pointer
bt_unfocus is button (can be any focusable VCL component)
I place this button usually on the left upper corner of App and set its size to 2x2 pixels
it is invisible at start
the idea is to set focus to it (but first unhide it so no exception is thrown)
and then hide it so it loses focus
work well in BCB5 and BDS2006 (did not used it with any other IDE)
as you can see most of the time is this component invisible
4.now when to call main_unfocus ?
when you go with mouse from outside to inside of your gfx area (OnMouseMove event)
or when you click on it
also you can combine this with remembering if the focus is or not in gfx area
that can be done with events like OnExit ...
or when you hit Esc while focus is inside edit box ...\
I am sure you grasp the idea and adjust this to your needs
Hope it helps
I am writing Qt application which plays a fade-in animation whenever the mouse is moved to a certain area in the screen, and a fade out animation whenever the mouse is moved out of that same area.
I've already found a similar question here in stack overflow, however, it does not quite answer my question. (similar question here)
If I install an event filter to the application, will I be able to see ALL the events in the application even if it's outside my widget window?
If not, I am aware of an alternative involving QWidget::grabMouse() inside a reimplementation of leaveEvent(). But if I do so, will I be able to interact with anything OUTSIDE my application?
edit: though i am using the Qt library, my application is only for deployment to Windows.
I'm fairly the certain the answer is no, because events outside of your widgets are handled by the OSs window manager (and propagated onto whatever application is in that space).
However you can get the mouse position anywhere on the screen by calling QCursor::pos(), you could poll at regular intervals to find out where the mouse is.
You could try creating a completely transparent window that stays on top of the area where you want to receive mouse events, with the Qt::WindowStaysOnTopHint, Qt::FramelessWindowHint and Qt::ToolTip flags (the last one might prevent the window from receiving the focus), the Qt::WA_TranslucentBackground attribute and the mouse tracking enabled.
If you are on Windows, you can create a global hook to receive every mouse message (right before it's sent to the window under the mouse pointer). Unfortunately I don't know whether this functionality exists in other OSs.
Pardon me, I am a newbie :)
Is it possible in Qt to create a custom window without borders but still draggable without holding down the Alt Key? I created a borderless window but in order to be able to drag it (on Linux) you have to hold down the alt key.
I was planning to create a window with rounded corners. Any one have any idea how to make this possible? Although, I think implementing the mouseMove, mousePress or something is a possible solution but I need some other solution.
Thanks
There is just one way to make the window manager move the window: Add a drag bar. If there is no drag bar, then your app must move the window itself by setting the new position (i.e. you must handle the mouse click+move events yourself).
The feature to move the window by pressing Alt is also a function of your window manager, not Qt.
Yes, there is a rounded window example somewhere using a clock which does this. Basically, you need to manage the mouse clicks yourself as Aaron says.
You may use QDecoration (for Embedded Linux) to make it: here is the example.
Detect that the mouse is held down on your window, then grab the events for the mouse moving around so you can move your window in sync with it. When user releases mouse button your task is over.