Results 1 to 4 of 4

Thread: Android screen res problem (it's always 640x480 instead of maximized) -- Qt 5.1, XP

  1. #1
    Join Date
    Jul 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Android screen res problem (it's always 640x480 instead of maximized) -- Qt 5.1, XP

    Good time of the day!

    I'm struggling for two days with a problem, which appears with the android build (latest Qt 5.1 and Qt Creator 2.7.2) on WinXP (but I think it don't matter), latest NDK, SDK, and WinAnt. In two words, android app always uses 640x480 resolution! The problem disappers once when I manually cleaned all the files built in the project, including *.pro.user, and rebuilt project from scratch. But one build later the problem returns (code changes cannot affect this, I'm sure). I didn't tried for more than one time to cleanup the project, because I think the problem is not in project properties (which hasn't changed between launches).

    Please at picture attached. The situation is not only on emulator occurs, but on the real device too. However, windows app running as expected.

    The actual code is the following:
    main.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2. #include "mainwidget.h"
    3.  
    4. #include <QApplication>
    5. #include <QTime>
    6.  
    7. int main(int argc, char *argv[])
    8. {
    9. QApplication app(argc, argv);
    10.  
    11. qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
    12.  
    13. MainWindow main_window;
    14. main_window.showMaximized();
    15. main_window.setCentralWidget(new MainWidget(&main_window));
    16.  
    17. return app.exec();
    18. }
    To copy to clipboard, switch view to plain text mode 

    mainwindow.h
    Qt Code:
    1. #ifndef MAINWINDOW_H
    2. #define MAINWINDOW_H
    3.  
    4. #include <QMainWindow>
    5.  
    6. class MainWindow : public QMainWindow
    7. {
    8. Q_OBJECT
    9.  
    10. public:
    11. MainWindow(QWidget *parent = 0);
    12. ~MainWindow();
    13. };
    14.  
    15. #endif // MAINWINDOW_H
    To copy to clipboard, switch view to plain text mode 

    mainwidget.h
    Qt Code:
    1. #ifndef MAINWIDGET_H
    2. #define MAINWIDGET_H
    3.  
    4. #include <QGraphicsView>
    5.  
    6. class QImage;
    7.  
    8. class MainWidget : public QGraphicsView
    9. {
    10. Q_OBJECT
    11. public:
    12. explicit MainWidget(QWidget *parent);
    13. protected:
    14. void drawBackground(QPainter *painter, const QRectF& rect);
    15.  
    16. private:
    17.  
    18. void createGameScene();
    19.  
    20. QGraphicsScene * scene;
    21. QWidget * parent;
    22. QGraphicsPixmapItem * splash, * score, * blueMeeple, * redMeeple;
    23.  
    24. private slots:
    25. void unsetSplash();
    26.  
    27. };
    28.  
    29. #endif // MAINWIDGET_H
    To copy to clipboard, switch view to plain text mode 

    [/code]

    mainwindow.cpp
    Qt Code:
    1. #include "mainwindow.h"
    2.  
    3. MainWindow::MainWindow(QWidget *parent)
    4. : QMainWindow(parent) {
    5. setStyleSheet("background-color: darkGrey;");
    6. }
    7.  
    8. MainWindow::~MainWindow() {
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 

    mainwidget.cpp
    Qt Code:
    1. #include "mainwidget.h"
    2.  
    3. #include <QGraphicsScene>
    4. #include <QGraphicsPixmapItem>
    5. #include <QTimer>
    6.  
    7. MainWidget::MainWidget(QWidget *parentWidget):
    8. QGraphicsView(parentWidget), parent(parentWidget), splash(0), score(0) {
    9. scene = new QGraphicsScene;
    10. scene->setItemIndexMethod(QGraphicsScene::NoIndex);
    11.  
    12. setScene(scene);
    13.  
    14. setCacheMode(CacheBackground);
    15. setViewportUpdateMode(FullViewportUpdate);
    16. setRenderHint(QPainter::Antialiasing);
    17.  
    18. scene->addItem(splash = new QGraphicsPixmapItem(QPixmap(":/images/DiscoveryArt.jpg")));
    19. QTimer::singleShot(2000, this, SLOT(unsetSplash()));
    20. }
    21.  
    22. void MainWidget::drawBackground(QPainter *painter, const QRectF& rect) {
    23. scene->setSceneRect(20, 20, parent->geometry().width() - 20, parent->geometry().height() - 20);
    24. QRectF scene_rect = scene->sceneRect();
    25.  
    26. if (splash)
    27. splash->setPos(mapToScene(rect.width()/2 - splash->pixmap().width()/2,
    28. rect.height()/2 - splash->pixmap().height()/2));
    29.  
    30. QRectF right_shadow(scene_rect.right(), scene_rect.top() + 5, 5, scene_rect.height());
    31. QRectF bottom_shadow(scene_rect.left() + 5, scene_rect.bottom(), scene_rect.width(), 5);
    32.  
    33. if (right_shadow.intersects(rect) || right_shadow.contains(rect))
    34. painter->fillRect(right_shadow, Qt::darkGray);
    35.  
    36. if (bottom_shadow.intersects(rect) || bottom_shadow.contains(rect))
    37. painter->fillRect(bottom_shadow, Qt::darkGray);
    38.  
    39. QLinearGradient gradient(scene_rect.topLeft(), scene_rect.bottomRight());
    40. gradient.setColorAt(0, Qt::white);
    41. gradient.setColorAt(1, Qt::lightGray);
    42. painter->fillRect(rect.intersected(scene_rect), gradient);
    43. painter->setBrush(Qt::NoBrush);
    44. painter->drawRect(scene_rect);
    45. }
    46.  
    47. void MainWidget::unsetSplash() {
    48. scene->removeItem(splash);
    49. delete splash;
    50. splash = 0;
    51. createGameScene();
    52. update();
    53. }
    54.  
    55. void MainWidget::createGameScene() {
    56. scene->addItem(score = new QGraphicsPixmapItem(QPixmap(":/images/DiscoveryScore.jpg")));
    57. score->setPos(mapToScene(scene->sceneRect().top(),scene->sceneRect().left()));
    58. scene->addItem(redMeeple = new QGraphicsPixmapItem(QPixmap(":/images/DiscoveryRedMeeple.png")));
    59. redMeeple->setPos(score->boundingRect().left() + 30, score->boundingRect().bottom() - 20);
    60. scene->addItem(blueMeeple = new QGraphicsPixmapItem(QPixmap(":/images/DiscoveryBlueMeeple.png")));
    61. blueMeeple->setPos(score->boundingRect().left() + 60, score->boundingRect().bottom() - 20);
    62. }
    To copy to clipboard, switch view to plain text mode 

    *.pro file
    Qt Code:
    1. #-------------------------------------------------
    2. #
    3. # Project created by QtCreator 2013-07-16T22:21:30
    4. #
    5. #-------------------------------------------------
    6.  
    7. QT += core gui
    8.  
    9. greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
    10.  
    11. TARGET = Discovery
    12. TEMPLATE = app
    13.  
    14. RESOURCES = discovery.qrc
    15.  
    16. SOURCES += main.cpp\
    17. mainwindow.cpp \
    18. mainwidget.cpp
    19.  
    20. HEADERS += mainwindow.h \
    21. mainwidget.h
    22.  
    23. CONFIG += mobility
    24. MOBILITY =
    25.  
    26. OTHER_FILES += \
    27. android/AndroidManifest.xml \
    28. android/res/layout/splash.xml \
    29. android/res/values/libs.xml \
    30. android/res/values/strings.xml \
    31. android/res/values-de/strings.xml \
    32. android/res/values-el/strings.xml \
    33. android/res/values-es/strings.xml \
    34. android/res/values-et/strings.xml \
    35. android/res/values-fa/strings.xml \
    36. android/res/values-fr/strings.xml \
    37. android/res/values-id/strings.xml \
    38. android/res/values-it/strings.xml \
    39. android/res/values-ja/strings.xml \
    40. android/res/values-ms/strings.xml \
    41. android/res/values-nb/strings.xml \
    42. android/res/values-nl/strings.xml \
    43. android/res/values-pl/strings.xml \
    44. android/res/values-pt-rBR/strings.xml \
    45. android/res/values-ro/strings.xml \
    46. android/res/values-rs/strings.xml \
    47. android/res/values-ru/strings.xml \
    48. android/res/values-zh-rCN/strings.xml \
    49. android/res/values-zh-rTW/strings.xml \
    50. android/src/org/kde/necessitas/ministro/IMinistro.aidl \
    51. android/src/org/kde/necessitas/ministro/IMinistroCallback.aidl \
    52. android/src/org/qtproject/qt5/android/bindings/QtActivity.java \
    53. android/src/org/qtproject/qt5/android/bindings/QtApplication.java \
    54. android/version.xml \
    55. android/AndroidManifest.xml \
    56. android/res/layout/splash.xml \
    57. android/res/values/libs.xml \
    58. android/res/values/strings.xml \
    59. android/res/values-de/strings.xml \
    60. android/res/values-el/strings.xml \
    61. android/res/values-es/strings.xml \
    62. android/res/values-et/strings.xml \
    63. android/res/values-fa/strings.xml \
    64. android/res/values-fr/strings.xml \
    65. android/res/values-id/strings.xml \
    66. android/res/values-it/strings.xml \
    67. android/res/values-ja/strings.xml \
    68. android/res/values-ms/strings.xml \
    69. android/res/values-nb/strings.xml \
    70. android/res/values-nl/strings.xml \
    71. android/res/values-pl/strings.xml \
    72. android/res/values-pt-rBR/strings.xml \
    73. android/res/values-ro/strings.xml \
    74. android/res/values-rs/strings.xml \
    75. android/res/values-ru/strings.xml \
    76. android/res/values-zh-rCN/strings.xml \
    77. android/res/values-zh-rTW/strings.xml \
    78. android/src/org/kde/necessitas/ministro/IMinistro.aidl \
    79. android/src/org/kde/necessitas/ministro/IMinistroCallback.aidl \
    80. android/src/org/qtproject/qt5/android/bindings/QtActivity.java \
    81. android/src/org/qtproject/qt5/android/bindings/QtApplication.java \
    82. android/version.xml
    To copy to clipboard, switch view to plain text mode 

    Please help me to solve the issue, I can't develop further with this behavior.
    Thanks in advance, Andrey
    Attached Images Attached Images

  2. #2
    Join Date
    Jul 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Android screen res problem (it's always 640x480 instead of maximized) -- Qt 5.1,

    This is a very very strange. I've cleaned the project once more, rebuilt Debug and Release version and no effect in emulator (the issue stays). But on real device release version works ok. I can think it's the problem of emulator, but anytimes screen resolution isn't ok on real device too. I'm confused

  3. #3
    Join Date
    Jul 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Android screen res problem (it's always 640x480 instead of maximized) -- Qt 5.1,

    It seems to be solved.
    I've refused from QMainWindow container and used QGraphicsView widget as a main widget, but this is not the main point. The problem was in not using resize:
    Qt Code:
    1.  
    2. MainWidget main_window;
    3. main_window.move(0,0);
    4. main_window.resize(desktop.availableGeometry().width(), desktop.availableGeometry().height());
    5. main_window.showMaximized();
    To copy to clipboard, switch view to plain text mode 

    But now I found another problem. I'll not spawn a new thread, will post here. Please look at the pictures attached.
    I use mingw complier, included in QtCreator + Qt5.1 distribution. All dynamic libraries are included into package (otherwise the app wouldn't start).

    On WinXP 32bit the scene and the splash are alright, but on Win7 64bit only the "starter tile" is on place, other items are off the scene rect...
    The one binary gives different results on the platforms. Maybe my use of QGraphicsView/QGraphicsScene is inappropriate?

    What can I do? Any help appreciated.

    Qt Code:
    1. void MainWidget::drawBackground(QPainter *painter, const QRectF& rect) {
    2. scene->setSceneRect(20, 20, geometry().width() - 20, geometry().height() - 20);
    3. QRectF scene_rect = scene->sceneRect();
    4.  
    5. if (splash) {
    6. splash->setPos(scene_rect.left() + scene_rect.width()/2 - splash->pixmap().width()/2,
    7. scene_rect.top() + scene_rect.height()/2 - splash->pixmap().height()/2);
    8. return;
    9. } else
    10. setCacheMode(CacheBackground);
    11.  
    12. QRectF right_shadow(scene_rect.right(), scene_rect.top() + 5, 5, scene_rect.height());
    13. QRectF bottom_shadow(scene_rect.left() + 5, scene_rect.bottom(), scene_rect.width(), 5);
    14.  
    15. if (right_shadow.intersects(rect) || right_shadow.contains(rect))
    16. painter->fillRect(right_shadow, Qt::darkGray);
    17.  
    18. if (bottom_shadow.intersects(rect) || bottom_shadow.contains(rect))
    19. painter->fillRect(bottom_shadow, Qt::darkGray);
    20.  
    21. QLinearGradient gradient(scene_rect.topLeft(), scene_rect.bottomRight());
    22. gradient.setColorAt(0, Qt::white);
    23. gradient.setColorAt(1, Qt::lightGray);
    24. painter->fillRect(scene_rect, gradient);
    25. painter->setBrush(Qt::NoBrush);
    26. painter->drawRect(scene_rect);
    27. }
    28.  
    29. // ...
    30. void MainWidget::createGameScene() {
    31. scene->addItem(score = new QGraphicsPixmapItem(QPixmap(":/images/DiscoveryScore.jpg")));
    32. score->setPos(scene->sceneRect().left(), scene->sceneRect().top());
    33. scene->addItem(redMeeple = new QGraphicsPixmapItem(QPixmap(":/images/DiscoveryRedMeeple.png")));
    34. redMeeple->setPos(scene->sceneRect().left() + 5,
    35. scene->sceneRect().top() + score->boundingRect().height() - redMeeple->boundingRect().height());
    36. scene->addItem(blueMeeple = new QGraphicsPixmapItem(QPixmap(":/images/DiscoveryBlueMeeple.png")));
    37. blueMeeple->setPos(scene->sceneRect().left() + 35,
    38. scene->sceneRect().top() + score->boundingRect().height() - blueMeeple->boundingRect().height());
    39.  
    40. TileItem * starter = new TileItem(this);
    41. starter->setTileNumber(0, true);
    42. starter->setI(84); starter->setJ(84); starter->setPut();
    43. starter->setFlag(QGraphicsItem::ItemIsMovable, false);
    44. starter->setPos(scene->sceneRect().left() + scene->sceneRect().width()/2 - starter->pixmap().width()/2,
    45. scene->sceneRect().top() + scene->sceneRect().height()/2 - starter->pixmap().height()/2);
    46. scene->addItem(starter);
    47. tilesMap[84][84] = starter;
    48.  
    49. for (qint8 i = 1; i < 84; ++i)
    50. restTiles << i;
    51.  
    52. TileItem * first_tile = new TileItem(this);
    53. first_tile->setTileNumber(qrand() % 83 + 1);
    54. first_tile->setPos(score->boundingRect().width() + scene->sceneRect().left() - first_tile->boundingRect().width(),
    55. score->boundingRect().height() + scene->sceneRect().top());
    56. scene->addItem(first_tile);
    57. }
    To copy to clipboard, switch view to plain text mode 
    Attached Images Attached Images

  4. #4
    Join Date
    Jul 2013
    Posts
    4
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: Android screen res problem (it's always 640x480 instead of maximized) -- Qt 5.1,

    Have found the solution. In deployment Windows documentation is nothing about need of adding imageformats/ folder in package. JPEG pictures were the problem without adding imageformats (png are ok).

Similar Threads

  1. [Android] volatile size of screen
    By franki in forum Qt Programming
    Replies: 3
    Last Post: 10th January 2013, 09:54
  2. problem with android emulator
    By jvlach in forum Newbie
    Replies: 0
    Last Post: 2nd February 2012, 13:46
  3. How to get splitter objects to fill the screen when maximized
    By jshafferman in forum Qt Programming
    Replies: 1
    Last Post: 8th March 2011, 22:53
  4. problem: Window moves on click when maximized
    By Toshikazu in forum Qt Programming
    Replies: 3
    Last Post: 30th January 2010, 23:22
  5. QGraphicsView.Rect is always 640x480
    By Andrewshkovskii in forum Newbie
    Replies: 5
    Last Post: 17th October 2009, 21:13

Tags for this Thread

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.