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
#include "mainwindow.h"
#include "mainwidget.h"
#include <QApplication>
#include <QTime>
int main(int argc, char *argv[])
{
qsrand
(QTime(0,
0,
0).
secsTo(QTime::currentTime()));
MainWindow main_window;
main_window.showMaximized();
main_window.setCentralWidget(new MainWidget(&main_window));
return app.exec();
}
#include "mainwindow.h"
#include "mainwidget.h"
#include <QApplication>
#include <QTime>
int main(int argc, char *argv[])
{
QApplication app(argc, argv);
qsrand(QTime(0,0,0).secsTo(QTime::currentTime()));
MainWindow main_window;
main_window.showMaximized();
main_window.setCentralWidget(new MainWidget(&main_window));
return app.exec();
}
To copy to clipboard, switch view to plain text mode
mainwindow.h
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
{
Q_OBJECT
public:
~MainWindow();
};
#endif // MAINWINDOW_H
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QMainWindow>
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow(QWidget *parent = 0);
~MainWindow();
};
#endif // MAINWINDOW_H
To copy to clipboard, switch view to plain text mode
mainwidget.h
#ifndef MAINWIDGET_H
#define MAINWIDGET_H
#include <QGraphicsView>
{
Q_OBJECT
public:
explicit MainWidget
(QWidget *parent
);
protected:
void drawBackground
(QPainter *painter,
const QRectF
& rect
);
private:
void createGameScene();
private slots:
void unsetSplash();
};
#endif // MAINWIDGET_H
#ifndef MAINWIDGET_H
#define MAINWIDGET_H
#include <QGraphicsView>
class QGraphicsScene;
class QImage;
class QGraphicsPixmapItem;
class MainWidget : public QGraphicsView
{
Q_OBJECT
public:
explicit MainWidget(QWidget *parent);
protected:
void drawBackground(QPainter *painter, const QRectF& rect);
private:
void createGameScene();
QGraphicsScene * scene;
QWidget * parent;
QGraphicsPixmapItem * splash, * score, * blueMeeple, * redMeeple;
private slots:
void unsetSplash();
};
#endif // MAINWIDGET_H
To copy to clipboard, switch view to plain text mode
[/code]
mainwindow.cpp
#include "mainwindow.h"
MainWindow
::MainWindow(QWidget *parent
) setStyleSheet("background-color: darkGrey;");
}
MainWindow::~MainWindow() {
}
#include "mainwindow.h"
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent) {
setStyleSheet("background-color: darkGrey;");
}
MainWindow::~MainWindow() {
}
To copy to clipboard, switch view to plain text mode
mainwidget.cpp
#include "mainwidget.h"
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QTimer>
MainWidget
::MainWidget(QWidget *parentWidget
): QGraphicsView(parentWidget
), parent
(parentWidget
), splash
(0), score
(0) {
setScene(scene);
setCacheMode(CacheBackground);
setViewportUpdateMode(FullViewportUpdate);
QTimer::singleShot(2000,
this,
SLOT(unsetSplash
()));
}
void MainWidget
::drawBackground(QPainter *painter,
const QRectF
& rect
) { scene->setSceneRect(20, 20, parent->geometry().width() - 20, parent->geometry().height() - 20);
QRectF scene_rect
= scene
->sceneRect
();
if (splash)
splash->setPos(mapToScene(rect.width()/2 - splash->pixmap().width()/2,
rect.height()/2 - splash->pixmap().height()/2));
QRectF right_shadow
(scene_rect.
right(), scene_rect.
top() + 5,
5, scene_rect.
height());
QRectF bottom_shadow
(scene_rect.
left() + 5, scene_rect.
bottom(), scene_rect.
width(),
5);
if (right_shadow.intersects(rect) || right_shadow.contains(rect))
painter->fillRect(right_shadow, Qt::darkGray);
if (bottom_shadow.intersects(rect) || bottom_shadow.contains(rect))
painter->fillRect(bottom_shadow, Qt::darkGray);
gradient.setColorAt(0, Qt::white);
gradient.setColorAt(1, Qt::lightGray);
painter->fillRect(rect.intersected(scene_rect), gradient);
painter->setBrush(Qt::NoBrush);
painter->drawRect(scene_rect);
}
void MainWidget::unsetSplash() {
scene->removeItem(splash);
delete splash;
splash = 0;
createGameScene();
update();
}
void MainWidget::createGameScene() {
score->setPos(mapToScene(scene->sceneRect().top(),scene->sceneRect().left()));
redMeeple->setPos(score->boundingRect().left() + 30, score->boundingRect().bottom() - 20);
blueMeeple->setPos(score->boundingRect().left() + 60, score->boundingRect().bottom() - 20);
}
#include "mainwidget.h"
#include <QGraphicsScene>
#include <QGraphicsPixmapItem>
#include <QTimer>
MainWidget::MainWidget(QWidget *parentWidget):
QGraphicsView(parentWidget), parent(parentWidget), splash(0), score(0) {
scene = new QGraphicsScene;
scene->setItemIndexMethod(QGraphicsScene::NoIndex);
setScene(scene);
setCacheMode(CacheBackground);
setViewportUpdateMode(FullViewportUpdate);
setRenderHint(QPainter::Antialiasing);
scene->addItem(splash = new QGraphicsPixmapItem(QPixmap(":/images/DiscoveryArt.jpg")));
QTimer::singleShot(2000, this, SLOT(unsetSplash()));
}
void MainWidget::drawBackground(QPainter *painter, const QRectF& rect) {
scene->setSceneRect(20, 20, parent->geometry().width() - 20, parent->geometry().height() - 20);
QRectF scene_rect = scene->sceneRect();
if (splash)
splash->setPos(mapToScene(rect.width()/2 - splash->pixmap().width()/2,
rect.height()/2 - splash->pixmap().height()/2));
QRectF right_shadow(scene_rect.right(), scene_rect.top() + 5, 5, scene_rect.height());
QRectF bottom_shadow(scene_rect.left() + 5, scene_rect.bottom(), scene_rect.width(), 5);
if (right_shadow.intersects(rect) || right_shadow.contains(rect))
painter->fillRect(right_shadow, Qt::darkGray);
if (bottom_shadow.intersects(rect) || bottom_shadow.contains(rect))
painter->fillRect(bottom_shadow, Qt::darkGray);
QLinearGradient gradient(scene_rect.topLeft(), scene_rect.bottomRight());
gradient.setColorAt(0, Qt::white);
gradient.setColorAt(1, Qt::lightGray);
painter->fillRect(rect.intersected(scene_rect), gradient);
painter->setBrush(Qt::NoBrush);
painter->drawRect(scene_rect);
}
void MainWidget::unsetSplash() {
scene->removeItem(splash);
delete splash;
splash = 0;
createGameScene();
update();
}
void MainWidget::createGameScene() {
scene->addItem(score = new QGraphicsPixmapItem(QPixmap(":/images/DiscoveryScore.jpg")));
score->setPos(mapToScene(scene->sceneRect().top(),scene->sceneRect().left()));
scene->addItem(redMeeple = new QGraphicsPixmapItem(QPixmap(":/images/DiscoveryRedMeeple.png")));
redMeeple->setPos(score->boundingRect().left() + 30, score->boundingRect().bottom() - 20);
scene->addItem(blueMeeple = new QGraphicsPixmapItem(QPixmap(":/images/DiscoveryBlueMeeple.png")));
blueMeeple->setPos(score->boundingRect().left() + 60, score->boundingRect().bottom() - 20);
}
To copy to clipboard, switch view to plain text mode
*.pro file
#-------------------------------------------------
#
# Project created by QtCreator 2013-07-16T22:21:30
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Discovery
TEMPLATE = app
RESOURCES = discovery.qrc
SOURCES += main.cpp\
mainwindow.cpp \
mainwidget.cpp
HEADERS += mainwindow.h \
mainwidget.h
CONFIG += mobility
MOBILITY =
OTHER_FILES += \
android/AndroidManifest.xml \
android/res/layout/splash.xml \
android/res/values/libs.xml \
android/res/values/strings.xml \
android/res/values-de/strings.xml \
android/res/values-el/strings.xml \
android/res/values-es/strings.xml \
android/res/values-et/strings.xml \
android/res/values-fa/strings.xml \
android/res/values-fr/strings.xml \
android/res/values-id/strings.xml \
android/res/values-it/strings.xml \
android/res/values-ja/strings.xml \
android/res/values-ms/strings.xml \
android/res/values-nb/strings.xml \
android/res/values-nl/strings.xml \
android/res/values-pl/strings.xml \
android/res/values-pt-rBR/strings.xml \
android/res/values-ro/strings.xml \
android/res/values-rs/strings.xml \
android/res/values-ru/strings.xml \
android/res/values-zh-rCN/strings.xml \
android/res/values-zh-rTW/strings.xml \
android/src/org/kde/necessitas/ministro/IMinistro.aidl \
android/src/org/kde/necessitas/ministro/IMinistroCallback.aidl \
android/src/org/qtproject/qt5/android/bindings/QtActivity.java \
android/src/org/qtproject/qt5/android/bindings/QtApplication.java \
android/version.xml \
android/AndroidManifest.xml \
android/res/layout/splash.xml \
android/res/values/libs.xml \
android/res/values/strings.xml \
android/res/values-de/strings.xml \
android/res/values-el/strings.xml \
android/res/values-es/strings.xml \
android/res/values-et/strings.xml \
android/res/values-fa/strings.xml \
android/res/values-fr/strings.xml \
android/res/values-id/strings.xml \
android/res/values-it/strings.xml \
android/res/values-ja/strings.xml \
android/res/values-ms/strings.xml \
android/res/values-nb/strings.xml \
android/res/values-nl/strings.xml \
android/res/values-pl/strings.xml \
android/res/values-pt-rBR/strings.xml \
android/res/values-ro/strings.xml \
android/res/values-rs/strings.xml \
android/res/values-ru/strings.xml \
android/res/values-zh-rCN/strings.xml \
android/res/values-zh-rTW/strings.xml \
android/src/org/kde/necessitas/ministro/IMinistro.aidl \
android/src/org/kde/necessitas/ministro/IMinistroCallback.aidl \
android/src/org/qtproject/qt5/android/bindings/QtActivity.java \
android/src/org/qtproject/qt5/android/bindings/QtApplication.java \
android/version.xml
#-------------------------------------------------
#
# Project created by QtCreator 2013-07-16T22:21:30
#
#-------------------------------------------------
QT += core gui
greaterThan(QT_MAJOR_VERSION, 4): QT += widgets
TARGET = Discovery
TEMPLATE = app
RESOURCES = discovery.qrc
SOURCES += main.cpp\
mainwindow.cpp \
mainwidget.cpp
HEADERS += mainwindow.h \
mainwidget.h
CONFIG += mobility
MOBILITY =
OTHER_FILES += \
android/AndroidManifest.xml \
android/res/layout/splash.xml \
android/res/values/libs.xml \
android/res/values/strings.xml \
android/res/values-de/strings.xml \
android/res/values-el/strings.xml \
android/res/values-es/strings.xml \
android/res/values-et/strings.xml \
android/res/values-fa/strings.xml \
android/res/values-fr/strings.xml \
android/res/values-id/strings.xml \
android/res/values-it/strings.xml \
android/res/values-ja/strings.xml \
android/res/values-ms/strings.xml \
android/res/values-nb/strings.xml \
android/res/values-nl/strings.xml \
android/res/values-pl/strings.xml \
android/res/values-pt-rBR/strings.xml \
android/res/values-ro/strings.xml \
android/res/values-rs/strings.xml \
android/res/values-ru/strings.xml \
android/res/values-zh-rCN/strings.xml \
android/res/values-zh-rTW/strings.xml \
android/src/org/kde/necessitas/ministro/IMinistro.aidl \
android/src/org/kde/necessitas/ministro/IMinistroCallback.aidl \
android/src/org/qtproject/qt5/android/bindings/QtActivity.java \
android/src/org/qtproject/qt5/android/bindings/QtApplication.java \
android/version.xml \
android/AndroidManifest.xml \
android/res/layout/splash.xml \
android/res/values/libs.xml \
android/res/values/strings.xml \
android/res/values-de/strings.xml \
android/res/values-el/strings.xml \
android/res/values-es/strings.xml \
android/res/values-et/strings.xml \
android/res/values-fa/strings.xml \
android/res/values-fr/strings.xml \
android/res/values-id/strings.xml \
android/res/values-it/strings.xml \
android/res/values-ja/strings.xml \
android/res/values-ms/strings.xml \
android/res/values-nb/strings.xml \
android/res/values-nl/strings.xml \
android/res/values-pl/strings.xml \
android/res/values-pt-rBR/strings.xml \
android/res/values-ro/strings.xml \
android/res/values-rs/strings.xml \
android/res/values-ru/strings.xml \
android/res/values-zh-rCN/strings.xml \
android/res/values-zh-rTW/strings.xml \
android/src/org/kde/necessitas/ministro/IMinistro.aidl \
android/src/org/kde/necessitas/ministro/IMinistroCallback.aidl \
android/src/org/qtproject/qt5/android/bindings/QtActivity.java \
android/src/org/qtproject/qt5/android/bindings/QtApplication.java \
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
Bookmarks