Qt isfullscreen = no such value - qt

i made a special videoplayer based of hikvision sdk with qtcreator in cpp
i have an void :
void QtVsPlayer::FullScr()
{
if (QtVsPlayer::isFullScreen()) {
QtVsPlayer::showNormal();
this->ui->menubar->setVisible(true);
if (!Zoomed)
this->ui->statusbar->setVisible(true);
} else {
QtVsPlayer::showFullScreen();
this->ui->menubar->setVisible(false);
this->ui->statusbar->setVisible(false);
}
return;
}
this void work, i have fullscreen video.
now in mousemove event i have
if (!this->ui->actionMasquer_les_controles->isChecked() and
WVideoCtrls->isHidden() and
this->ui->actionAuto_hide_controls->isChecked()) {
if(!Zoomed and QtVsPlayer::isFullScreen() == false)
ui->statusbar->setVisible(true);
WVideoCtrls->show();
WVideoCtrls->activateWindow();
WVideoCtrls->raise();
this->centralWidget()->lower();
this->centralWidget()->stackUnder(WVideoCtrls);
}
if (QtVsPlayer::cursor() == Qt::BlankCursor) {
QtVsPlayer::unsetCursor();
}
return;
the goal is to display videocontrols, like play, pause and so on, but not the status bar in full screen, but it is shown, zoomed is false but isfullscreen is no such value
i tried ui->centralwidget, this->isfullscreen, is->fulsreen, & , &&, and, but statusbar is displayed in fullscreen when mouse move and hide after my timer hider

Related

How can I check a WheelEvent is from mouse wheel or touchpad in qml on Windows?

I tried this var isTrackPad = wheel.pixelDelta !== Qt.point(0,0); as this says.
But it seems pixelDelta works only on Mac. Is there other method to check if a wheel event is from mouse wheel or touchpad on Windows?
onWheel: {
var horizontal = false;
var isTrackPad = wheel.pixelDelta !== Qt.point(0,0);
if (Math.abs(wheel.angleDelta.x) > Math.abs(wheel.angleDelta.y)) {
delta = wheel.angleDelta.x
horizontal = true
}
else {
delta = wheel.angleDelta.y
}
if ((isTrackPad && horizontal) || (!isTrackPad && wheel.modifiers === xxx.ScrollModifiersH)) {
...
}
}
You could try WheelHandler instead like the following. I can't tell if it will work on Windows as I'm using Linux and there the Mouse is the same as the Touchpad.
acceptedDevices
Note: Some non-mouse hardware (such as a touch-sensitive Wacom tablet,
or a Linux laptop touchpad) generates real wheel events from gestures.
WheelHandler will respond to those events as wheel events even if
acceptedDevices remains set to its default value.
WheelHandler {
acceptedDevices: PointerDevice.Mouse
onWheel: console.log("WheelHandler", "Mouse")
}
WheelHandler {
acceptedDevices: PointerDevice.TouchPad
onWheel: console.log("WheelHandler", "TouchPad")
}
Or you can get the QInputDevice::DeviceType from the WheelEvent. But same story here, if your OS doesn't make a difference between mouse or touchpad it will always give you QInputDevice::DeviceType::Mouse. The matching enum in QML is PointerDevice.Mouse.
MouseArea {
anchors.fill: parent
onWheel: function(wheelEvent) {
console.log("device", wheelEvent.device.type)
}
}

graphicsview receives mouse event before the item

I have implemented the panning view on the QGraphicsView, using the mouse move event using
void View::mouseMoveEvent(QMouseEvent* event) {
pan();
QGraphicsView::mouseMoveEvent(event);
}
and in the scene of this view I have added few items where some of the items are resizable, so I implemented
void Item::mouseMoveEvent(QGraphicsSceneMouseEvent *event)
{
if(m_resizeMode)
{
resize();
e->accept();
}
}
I tried to filter the mouse move not to propagate to any further using e->accept()
but my View mouseMove event has been called first , so when ever I tried to resize the item, the view started to pan all the way.
How can I avoid this event propagation from view to scene.
You can call the base class implementation of the QGraphicsView and check if the event is accepted. However I would do this in the mousePressEvent instead of the mouseMoveEvent. After all this is where you determine if you should resize an item or do some panning. This is how I do something similar in my project:
void View::mousePressEvent(QMouseEvent *event)
{
...
QGraphicsView::mousePressEvent(event);
if(event->isAccepted())
move = false;
else
move = true;
}
void View::mouseMoveEvent(QMouseEvent *event)
{
if(!move)
{
QGraphicsView::mouseMoveEvent(event);
return;
}
... // you would do the panning here
QGraphicsView::mouseMoveEvent(event);
}
void View::mouseReleaseEvent(QMouseEvent *event)
{
if(!move)
{
QGraphicsView::mouseReleaseEvent(event);
return;
}
else
{
...
move = false;
}
QGraphicsView::mouseReleaseEvent(event);
}
The view will always receive the mouse event first.
So, in the view, check to see if the mouse is over an item before allowing it to pan by getting the mouse pos in scene coordinates and retrieving the items at that position with QGraphicsScene::items( )

How to ensure, the entire area in QScrollArea was displayed?

I'm displaying some information to the user in QScrollArea.
The user should have seen all contents, before she can proceed (at least the content should have been scrolled to the end)
How could I detect this in an easily?
Is the reimplementing of virtual void scrollContentsBy (int dx,int dy) the only way?
EDIT
I was able to solve it, but had to use some workarounds:
Scroll-action value sent by the signal actionTriggered(int) had never the value QAbstractSlider::SliderToMaximum (Qt4.8, Windows 7). So I've checked manually, if the slider value is close to maximum.
Even if scroll-bar widget was dragged by mouse till the bottom, the value of the scroll-bar is never the maximum. Only if the scroll-bar widget is moved by any other event such as arrow-down or mouse wheel, the value may become maximum. I've work-arounded it with recheckPosition()
I hope, there are better solutions.
void NegativeConfirmation::recheckPosition()
{
processScrollAction(1);
}
void NegativeConfirmation::processScrollAction( int evt)
{
if ( evt == QAbstractSlider::SliderToMaximum) // Have not managed to receive this action
{
ui->bConfirm->setEnabled(true);
}
//Another approach
QWidget * sw = ui->scrollArea->widget();
if ( sw ) //any content at all ?
{
QScrollBar * sb = ui->scrollArea->verticalScrollBar();
if ( sb )
{
int sbv = sb->value();
int sbm = sb->maximum()-10;
if ( sbm>0 && sbv >= sbm )
{
ui->bConfirm->setEnabled(true);
}
else
{
QTimer::singleShot(1000, this, SLOT(recheckPosition()));
}
}
}
}
QScrollArea inherits QAbstractSlider which provides this signal: -
void QAbstractSlider::actionTriggered(int action)
Where action can be QAbstractSlider::SliderToMaximum.
I expect you can connect to the this signal and test when the action is QAbstractSlider::SliderToMaximum, representing that the user has scrolled to the bottom.

How to detect if a window has been activated?

Focus events don't work because they're not sent if you activate your window by clicking on its non-client frame. Also, if you click the internal components of the window THEY will get the focus event, not your window, but the window will still be activated, even if it wasn't active or focused before.
The event you want is QEvent::WindowActivate. Override event() to process it:
bool YourWidget::event(QEvent *e)
{
if (e->type() == QEvent::WindowActivate) {
// window was activated
}
return QWidget::event(e);
}
Qt provides several virtual event handling functions you can use. Since the activation of a window changes its state, you want to handle some change events:
void MyWidget::changeEvent(QEvent * e) {
if(e->type() == QEvent::ActivationChange && this->isActiveWindow()) {
// .. this is now the active window
}
}
References
changeEvent
isActiveWindow

QT window ActivationChange event under linux

I have the following issue: I have a "splash" like window coming with my application and it has a few buttons on it for opening the last project, creating a new one, etc... On pressing, these buttons hide the window and do the stuff.
This window is created with the following code and flags:
void MainWindowButtonDialog::showMe()
{
setModal(false);
setWindowFlags(Qt::SplashScreen | Qt::CustomizeWindowHint |
Qt::WindowStaysOnTopHint | Qt::X11BypassWindowManagerHint);
show();
}
The window is called m_btnDlg.
Now, due to requests from the clients when the application loses focus I need to hide this window, and when the application gets focus I need to re-show it. This is done by the following code:
void MainWindow::changeEvent(QEvent *e)
{
if( e->type() == QEvent::WindowStateChange )
{
if( isMinimized() )
{
if(m_btndlg && m_btndlg->isVisible())
{
m_btndlg->hide();
m_splashWasVisible = true;
}
}
else
{
if(m_splashWasVisible)
{
m_btndlg->show();
m_splashWasVisible = false;
}
}
}
if(e->type() == QEvent::ActivationChange)
{
if(!isActiveWindow())
{
if(m_btndlg && m_btndlg->isVisible() && !m_btndlg->isActiveWindow())
{
m_btndlg->hide(); // *****
m_splashWasVisible = true;
}
}
else
{
if(m_splashWasVisible)
{
m_btndlg->show();
m_splashWasVisible = false;
}
}
}
QMainWindow::changeEvent(e);
}
Now to the problem: the code above worked perfectly till now (both under Linux - Gnome 2.x on CentOS 5.x, and KDE 3.x and also Windows, all interesting versions). Recently the client has installed a few Fedora systems and Gnome 3, KDE 4, etc... suddenly the application behaves funnily. When I press the the button to create a new project it hides the splash window and nothing happens. The line marked with ** above is the one responsible. It seems that these new window managers send the activation events out of order.
Has anyone experience with this?
(More Code available on request). We use Qt 4.6.3
thanks.
You should try the application level events QEvent::ApplicationActivate and QEvent::ApplicationDeactivate with an event filter installed on qApp.
These events are fired when the application focus changes or the application window is minimized.
MainWindow::MainWindow() {
qApp->installEventFilter(this);
}
bool MainWindow::eventFilter(QObject *obj, QEvent *evt)
{
if(obj==qApp && ( evt->type() == QEvent::ApplicationActivate
|| evt->type() == QEvent::ApplicationDeactivate))
{
bool shouldHide = evt->type() == QEvent::ApplicationDeactivate;
if (shouldHide) {
m_splashWasVisible = m_btndlg && m_btndlg->isVisible();
if(m_splashWasVisible)
m_btndlg->hide();
} else {
if(m_splashWasVisible)
m_btndlg->show();
}
}
return QMainWindow::eventFilter(obj, evt);
}
Alternatively, you could display the splash window as part of the main window on top of all other widgets by setting the main window as its parent, and using QWidget::raise().

Resources