Results 1 to 4 of 4

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

Threaded View

Previous Post Previous Post   Next Post Next Post
  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

Similar Threads

  1. [Android] volatile size of screen
    By franki in forum Qt Programming
    Replies: 3
    Last Post: 10th January 2013, 08:54
  2. problem with android emulator
    By jvlach in forum Newbie
    Replies: 0
    Last Post: 2nd February 2012, 12: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, 21:53
  4. problem: Window moves on click when maximized
    By Toshikazu in forum Qt Programming
    Replies: 3
    Last Post: 30th January 2010, 22:22
  5. QGraphicsView.Rect is always 640x480
    By Andrewshkovskii in forum Newbie
    Replies: 5
    Last Post: 17th October 2009, 20: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.