Results 1 to 20 of 20

Thread: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

  1. #1
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    So I am looking at QScreenOrientationChangeEvent However I cannot seem to find *any* info on it. How do I implement it? Anybody some pointers please?

    I tried this code in my mainwindow but it doesn't even fire.
    Qt Code:
    1. bool MainWindow::event(QEvent *event)
    2. {
    3. if (event->type() == QEvent::OrientationChange)
    4. {
    5. mainwidth = desk.width(); // how do it get this stuff?
    6. mainheight = desk.height();
    7. }
    8. return QWidget::event(event);
    9. }
    To copy to clipboard, switch view to plain text mode 

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    QScreen has a signal for orientation change.

    You can get the screen(s) through QGuiApplication

    Cheers,
    _

  3. #3
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Thanks for your answer.

    This also works
    Qt Code:
    1. connect(QApplication::desktop(), SIGNAL(resized(int)), this, SLOT(resized(int)));
    To copy to clipboard, switch view to plain text mode 
    but I need the orientation event in a qdialog too.

    [rant] It can't be that the most important event on andriod has gone. All effort seems to go to xml while qwidget is not only ignored but even crippled. There's lots of code which just can't be ported to 5.3 this way.

    Still hoping for a solution, else I will have to go back to 5.2 even if 5.3 is more stable on android.

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Are you sure you are looking at the right receiver object for the event?
    Try installing an event filter on the QApplication instance and see which object the event is sent to. I would imagine that it is sent to the QScreen, not any specific top level window.

    Cheers,
    _

  5. #5
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Thanks for your help.
    Which event are you talking about? If you mean the QScreenOrientationChangeEvent which I have my hopes on. I tried it on the mainwindow and on a drawing class derived from qwidget.
    But as the name suggests you could very well be right. In which case this event is of no use to me. It seems that widgets really are deprecated.
    Back to 5.2 for the last update and bye to qt android.

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Quote Originally Posted by Cremers View Post
    Thanks for your help.
    Which event are you talking about? If you mean the QScreenOrientationChangeEvent which I have my hopes on.
    Yes.

    Quote Originally Posted by Cremers View Post
    I tried it on the mainwindow and on a drawing class derived from qwidget.
    It might not be sent to windows since it is not related to windows. It affects screens so it is likely sent to screen objects.

    Quote Originally Posted by Cremers View Post
    But as the name suggests you could very well be right. In which case this event is of no use to me.
    How so?

    Quote Originally Posted by Cremers View Post
    It seems that widgets really are deprecated.
    Nope.

    Cheers,
    _

  7. #7
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Quote Originally Posted by anda_skoa View Post
    How so?
    Because I need it in a qwidget and qdialog too. For instance I want a dialog to redraw it's stuff when rotation changes.

    This was told to me by a fellow qt android dev:
    As far as i know and i have been told, widgets are de facto deprecated on qt5/android.
    Widgets are still working but there's little work done on them for android. For instance now there's no way to tell an android rotation anymore. Don't get me wrong, I love qt but in case of android you have to go the xml way and not the widget way. Only wish qt would be more clear about it.
    Last edited by Cremers; 23rd August 2014 at 16:48.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Quote Originally Posted by Cremers View Post
    Because I need it in a qwidget and qdialog too. For instance I want a dialog to redraw it's stuff when rotation changes.
    And that is a problem because?

    Quote Originally Posted by Cremers View Post
    This was told to me by a fellow qt android dev:
    I guess most Android devices are phones or tablets, thus better being served by QtQuick, but Qt/Android is not going to remove the widget module or related infrastructure code.

    Quote Originally Posted by Cremers View Post
    Widgets are still working but there's little work done on them for android. For instance now there's no way to tell an android rotation anymore.
    So you are saying that QScreen:rientationChanged() is not emitted?

    Quote Originally Posted by Cremers View Post
    Don't get me wrong, I love qt but in case of android you have to go the xml way and not the widget way.
    You don't have to use XML .ui files to create widget scenes, it is always possible to use C++. Designer is usually just way more convenient.

    Cheers,
    _

  9. #9
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Excuse me for being blunt but I would like to get to the point of this. How do I handle a screen rotation in a qdialog so it can redraw it's stuff? I used to catch this inside QWidget::resizeEvent for the dialog but in 5.3 it doesn't fire anymore, nor for any other qwidget deratives.

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Quote Originally Posted by Cremers View Post
    Excuse me for being blunt but I would like to get to the point of this. How do I handle a screen rotation in a qdialog so it can redraw it's stuff?
    Qt has a concept called signal&slots.
    An "active" object detects some change, e.g. a timer running out, data arriving for a socket, or in this case a screen changing its orientation.
    To allow user code to react to that change it emits a signal, basically starting a callback invocation procedure.

    Any object, usually a user created one, in your case probably your dialog, has a method called a slot, that can be connected to the sender object's signal.
    When the sender emits its signal, all connected receiver slots are invoked.

    You will find this pattern a lot in Qt applications, it is quite easy to use.

    Cheers,
    _

  11. #11
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Yes I know I can make it work. My point is, it was easy in 5.2 because screenrotation was propageted to the widgets, it's not anymore, functionality for widgets in android is removed in favour of other things.

  12. #12
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Quote Originally Posted by Cremers View Post
    Yes I know I can make it work. My point is, it was easy in 5.2 because screenrotation was propageted to the widgets, it's not anymore
    Are you sure. In another comment you wrote that you had implemented resizeEvent().

    Quote Originally Posted by Cremers View Post
    functionality for widgets in android is removed in favour of other things.
    The only two classes in QtWidgets, aside from the platform style plugin, with Android specific code are QTextBrowser and QLineEdit.
    Neither case has anything to do with orientation change.

    On further search there is actually no orientation change occurence in QtWidgets at all, not surprising given that it is already handled at QtGui level.

    Cheers,
    _

  13. #13
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Quote Originally Posted by anda_skoa View Post
    Are you sure. In another comment you wrote that you had implemented resizeEvent().
    That's in 5.2 yes.
    On further search there is actually no orientation change occurence in QtWidgets at all, not surprising given that it is already handled at QtGui level.
    In 5.2 there is. The resizeevent can/should be used for the rotation. So my point is, it was relatively easy to get the event but no so anymore.
    Widgets on android don't get full support, some can not be used at all in android, it's a well known fact in the necessitas google group, the emphasis is on qtquick.
    I have gone back to 5.2, sadly I don't see any future in qt for android with widgets so it'll be an upgrade and then looking for something else. A pity. Really.

  14. #14
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Quote Originally Posted by Cremers View Post
    That's in 5.2 yes.
    Ok, just verfying that you did not have working code for handling the orientation change event and that no longer works.

    Quote Originally Posted by Cremers View Post
    In 5.2 there is. The resizeevent can/should be used for the rotation.
    So you were relying on an unrelated event being delivered as a side effect of the orientation change.
    Have you tried using propery orientation change handling in code compiled against 5.2 and verified that this no longer works in 5.3?

    Quote Originally Posted by Cremers View Post
    So my point is, it was relatively easy to get the event but no so anymore.
    You have confirmed that you did not check for the event, but now you claim you did?
    I find that pretty contradictory.

    If QScreen does not emit the orientation change signal in Qt5.3 then this is a bug and should be reported.
    And it would not be a QtWidget specifc bug since it would affect anything that uses QtGui.

    Cheers,
    _

  15. #15
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    In reading this thread, I am puzzled as to how the OP was able to use QResizeEvent to determine that the screen had been rotated. QResizeEvent contains absolutely no screen orientation information at all, just the old and new sizes of the *widget* to which it applies. If the OP was simply making the assumption that the orientation had changed by comparing width and height of the new and old rects, then that is a flawed interpretation of the event.

    I think I would be surprised if the resize event was sent at all after an orientation change, because the *widget* has not in fact undergone a change in size.

    I also fail to see why a connection can't be made to the QScreen::orientationChanged() signal from anywhere:

    Qt Code:
    1. QScreen * pScreen = QGuiApplication::primaryScreen();
    2. connect( pScreen, SIGNAL( orientationChanged( int ) ), this, SLOT( onScreenOrientationChanged( int ) ) );
    To copy to clipboard, switch view to plain text mode 
    where, of course, you have to write the slot code in your widget class to do whatever is required. Also note this important factoid from the docs:

    void QScreen::setOrientationUpdateMask(Qt::ScreenOrient ations mask)

    Sets the orientations that the application is interested in receiving updates for in conjunction with this screen.

    For example, to receive orientation() updates and thus have orientationChanged() signals being emitted for LandscapeOrientation and InvertedLandscapeOrientation, call setOrientationUpdateMask() with mask set to Qt::LandscapeOrientation | Qt::InvertedLandscapeOrientation.

    The default, 0, means no orientationChanged() signals are fired.
    (emphasis mine).

    If I were to make a guess, if the application sets this flag at the outset, there would be no need to handle orientationChanged() signals at all. The app would probably automatically rotate everything on its own. That the default setting is to ignore orientation changes implies that rotating the screen would have no effect on the app's orientation.
    Last edited by d_stranz; 24th August 2014 at 21:51.

  16. #16
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Quote Originally Posted by d_stranz View Post
    In reading this thread, I am puzzled as to how the OP was able to use QResizeEvent to determine that the screen had been rotated.
    Be cause that was the way things were done in 5.2 as someone with experience in qt android would know.
    If I were to make a guess, if the application sets this flag at the outset, there would be no need to handle orientationChanged() signals at all. The app would probably automatically rotate everything on its own. That the default setting is to ignore orientation changes implies that rotating the screen would have no effect on the app's orientation.
    Nice theory. And of course it will also automatically redraw/reposition all stuff to the new resolutions as is needed. Do you know what you are talking about?
    Last edited by Cremers; 25th August 2014 at 09:13.

  17. #17
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Quote Originally Posted by Cremers View Post
    Be cause that was the way things were done in 5.2 as someone with experience in qt android would know.
    Are you sure this was documented behavior and not just some incidental side effect?

    Cheers,
    _

  18. #18
    Join Date
    Jan 2008
    Location
    Alameda, CA, USA
    Posts
    5,316
    Thanks
    314
    Thanked 870 Times in 857 Posts
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    And of course it will also automatically redraw/reposition all stuff to the new resolutions as is needed.
    There is no resolution change upon screen rotation. There *is* a change in screen dimension if the screen is rectangular. And yes, if you've used layouts and size hints correctly, Qt is pretty good at automatically repositioning things to fit a new layout size. Of course, if you've made your widgets too big to fit on screen, aren't using layouts, or have set size constraints in such a way that Qt is prevented from doing its thing, then it is entirely possible that you'll see undesirable effects.

    Do you know what you are talking about?
    Usually.

  19. #19
    Join Date
    May 2012
    Posts
    57
    Thanks
    11
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows Android

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    I tried it.
    Qt Code:
    1. // in constructor
    2. QScreen * screen = QGuiApplication::primaryScreen();
    3. connect(screen, SIGNAL(orientationChanged(Qt::ScreenOrientation)), this, SLOT(onRotate(Qt::ScreenOrientation)));
    4. screen->setOrientationUpdateMask(Qt::PortraitOrientation| Qt::LandscapeOrientation| Qt::InvertedPortraitOrientation| Qt::InvertedLandscapeOrientation);
    5.  
    6. void MainWindow::onRotate(Qt::ScreenOrientation)
    7. {
    8. QScreen * screen = QGuiApplication::primaryScreen();
    9. QRect r = screen->availableGeometry();
    10. draw(r.height(), r.width());
    11. }
    To copy to clipboard, switch view to plain text mode 

    draw(width, height) is my own stuff. Note I had to reverse the order of the parameters in the call, checked with a showMessage() though, that is the correct order, believe me, i didn't believe it myself, i tried the reverse.

    Result is: I get correct screensizes, but when I start in portrait, then rotate, I get the correct drawing but the right side of the screen stays black.
    Starting in landscape the same, there the lower part stays black after rotate.
    It just refuses to paint in the area that wasn't painted in on startup.
    Tried several things, checked the onpaint event if it provides the correct sizes, it does, so I'm stuck and back to 5.2.1 for the moment, there it works (via the onresize).
    Last edited by Cremers; 30th August 2014 at 14:26.

  20. #20
    Join Date
    Jan 2012
    Location
    Dortmund, Germany
    Posts
    159
    Thanks
    69
    Thanked 10 Times in 8 Posts
    Qt products
    Qt4
    Platforms
    Windows Android

    Default Re: Android: resizeevent in qt 5.3.1 does not detect orientation change anymore

    Hi,
    the time when the signal is emitted might be too late in the chain to use it for painting/polishing (i.e. some polishing might be already done).

    Two ideas:
    - Call the redraw with a QTimer:SingleShot
    A few ms will do, this is a quick and dirty thing to get a different thread do the job (the timer thread). Might work.

    - Force polishing. I've had a similar problem and that was the solution. I now use
    Qt Code:
    1. void WhatEverClass::unpolishAll(QObject *object)
    2. {
    3. if (!object)
    4. return;
    5. QWidget* w=dynamic_cast<QWidget *>(object);
    6. if (w) {
    7. w->style()->unpolish(w);
    8. }
    9. foreach (QObject *child, object->children()) {
    10. unpolishAll(child);
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 
    and / or
    Qt Code:
    1. whatEverObject->ensurePolished();
    To copy to clipboard, switch view to plain text mode 
    to force Qt to do its homework.

    I'm not sure if this will help here. I am pretty sure though, that I have made some mistakes when trying to explain the workarounds (please correct me!), but they have helped me in similar moments of despair, so it might work for you.

    Best regards,
    Sebastian

Similar Threads

  1. detect system time change
    By ahmdsd_ostora in forum Qt Programming
    Replies: 5
    Last Post: 29th October 2019, 12:04
  2. Replies: 1
    Last Post: 19th July 2013, 23:20
  3. QLineedit's text orientation change
    By vivek.panchal in forum Qt Programming
    Replies: 0
    Last Post: 4th March 2013, 13:56
  4. QFileSystemWatcher best way to detect change
    By hakermania in forum Qt Programming
    Replies: 2
    Last Post: 12th October 2011, 15:51
  5. Change QTableView orientation
    By r2d2u2 in forum Qt Programming
    Replies: 2
    Last Post: 31st May 2010, 10:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.