aguayro
10th July 2013, 02:11
I have an app with a QTabWidget containing 5 tabs. Each tab has 1 QGraphicsView.
The first time i run the application, the fitInView function only works on active QGraphicsView, after I've change to all tabs, the fitInView function keeps working correctly.
It's like i have to use it at least 1 time with each tab active for got it working correctly.
Any idea what could be wrong? Something about fitInView or QGraphicsView that i should to know?
It's a lot of code, i don't know what to copy/paste >_<, this is the code used each time an image is loaded (this is the code of 1 of the 5 QGraphicsView, all are almost the same):
Header File
QStringList flyerList;
QGraphicsScene FlyerScene;
QGraphicsPixmapItem *flyerItem;
QTimer flyerTimer;
int FlyerSwapPos;
Fragment of cpp file:
void RetroSuite::MEDIA_Flyer() {
FlyerScene.clear();
flyerList.clear();
QSettings inisets(QString("data/systemdata/%1/%2.ini").arg(CurrType).arg(CurrSID), QSettings::IniFormat);
QString folder = inisets.value("Flyer/Folder").toString();
if (!folder.isEmpty() && folder.length() > 3) {
QDirIterator iter(folder, QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (iter.hasNext()) {
QFileInfo nextfile = iter.next();
if ((CurrGameName.contains(nextfile.completeBaseName( )) && CurrType != "Arcade") || (nextfile.completeBaseName() == ( CurrLaunchName) && CurrType == "Arcade")) {
flyerList << nextfile.absoluteFilePath();
}
}
if (flyerList.count() > 0) {
flyerItem = FlyerScene.addPixmap(QPixmap());
flyerItem->setPixmap(QPixmap(flyerList.at(0)));
ui->flyerView->setFlyerItem(flyerItem);
FlyerScene.setSceneRect(QPixmap(flyerList.at(0)).r ect());
FlyerSwapPos = 0;
if (inisets.value("Flyer/Fit").toBool()) {
ui->flyerView->setTransform(QTransform());
ui->flyerView->fitInView(flyerItem, Qt::KeepAspectRatio);
ui->flyerView->show();
} else if (inisets.value("Flyer/Scaled").toBool()) {
ui->flyerView->resetTransform();
switch( inisets.value("Flyer/SizeScale").toInt() ) {
case 0:
ui->flyerView->scale(0.1, 0.1);
break;
case 1:
ui->flyerView->scale(0.2, 0.2);
break;
case 2:
ui->flyerView->scale(0.3, 0.3);
break;
case 3:
ui->flyerView->scale(0.4, 0.4);
break;
case 4:
ui->flyerView->scale(0.5, 0.5);
break;
case 5:
ui->flyerView->scale(0.6, 0.6);
break;
case 6:
ui->flyerView->scale(0.7, 0.7);
break;
case 7:
ui->flyerView->scale(0.8, 0.8);
break;
case 8:
ui->flyerView->scale(0.9, 0.9);
break;
case 9:
ui->flyerView->scale(1.0, 1.0);
break;
}
} else {
ui->flyerView->setTransform(QTransform());
}
}
if (inisets.value("Flyer/SwapAuto").toBool()) {
flyerTimer->start( inisets.value("Flyer/SwapTimer").toInt() * 1000 );
}
}
}
I'm really lost with this, i have no idea what is wrong.
The first time i run the application, the fitInView function only works on active QGraphicsView, after I've change to all tabs, the fitInView function keeps working correctly.
It's like i have to use it at least 1 time with each tab active for got it working correctly.
Any idea what could be wrong? Something about fitInView or QGraphicsView that i should to know?
It's a lot of code, i don't know what to copy/paste >_<, this is the code used each time an image is loaded (this is the code of 1 of the 5 QGraphicsView, all are almost the same):
Header File
QStringList flyerList;
QGraphicsScene FlyerScene;
QGraphicsPixmapItem *flyerItem;
QTimer flyerTimer;
int FlyerSwapPos;
Fragment of cpp file:
void RetroSuite::MEDIA_Flyer() {
FlyerScene.clear();
flyerList.clear();
QSettings inisets(QString("data/systemdata/%1/%2.ini").arg(CurrType).arg(CurrSID), QSettings::IniFormat);
QString folder = inisets.value("Flyer/Folder").toString();
if (!folder.isEmpty() && folder.length() > 3) {
QDirIterator iter(folder, QDir::Files | QDir::NoDotAndDotDot, QDirIterator::Subdirectories);
while (iter.hasNext()) {
QFileInfo nextfile = iter.next();
if ((CurrGameName.contains(nextfile.completeBaseName( )) && CurrType != "Arcade") || (nextfile.completeBaseName() == ( CurrLaunchName) && CurrType == "Arcade")) {
flyerList << nextfile.absoluteFilePath();
}
}
if (flyerList.count() > 0) {
flyerItem = FlyerScene.addPixmap(QPixmap());
flyerItem->setPixmap(QPixmap(flyerList.at(0)));
ui->flyerView->setFlyerItem(flyerItem);
FlyerScene.setSceneRect(QPixmap(flyerList.at(0)).r ect());
FlyerSwapPos = 0;
if (inisets.value("Flyer/Fit").toBool()) {
ui->flyerView->setTransform(QTransform());
ui->flyerView->fitInView(flyerItem, Qt::KeepAspectRatio);
ui->flyerView->show();
} else if (inisets.value("Flyer/Scaled").toBool()) {
ui->flyerView->resetTransform();
switch( inisets.value("Flyer/SizeScale").toInt() ) {
case 0:
ui->flyerView->scale(0.1, 0.1);
break;
case 1:
ui->flyerView->scale(0.2, 0.2);
break;
case 2:
ui->flyerView->scale(0.3, 0.3);
break;
case 3:
ui->flyerView->scale(0.4, 0.4);
break;
case 4:
ui->flyerView->scale(0.5, 0.5);
break;
case 5:
ui->flyerView->scale(0.6, 0.6);
break;
case 6:
ui->flyerView->scale(0.7, 0.7);
break;
case 7:
ui->flyerView->scale(0.8, 0.8);
break;
case 8:
ui->flyerView->scale(0.9, 0.9);
break;
case 9:
ui->flyerView->scale(1.0, 1.0);
break;
}
} else {
ui->flyerView->setTransform(QTransform());
}
}
if (inisets.value("Flyer/SwapAuto").toBool()) {
flyerTimer->start( inisets.value("Flyer/SwapTimer").toInt() * 1000 );
}
}
}
I'm really lost with this, i have no idea what is wrong.