[SOLVED]Is it a BUG or bad technique?
-
wrote on 23 Jun 2014, 11:20 last edited by
Hello!
I need to replace widget from one layout to other after rotation ASUS Pad T300 (Android 4.2).
I do it such
@void ControlDialog::resizeEvent(QResizeEvent *event)
{
if(width()>height()){
if(ui->horizontalLayoutUp->indexOf(ui->grpBoxAED)==-1){ui->verticalLayoutDown->removeWidget(ui->grpBoxAED); ui->horizontalLayoutUp->addWidget(ui->grpBoxAED); } } else{ if(ui->verticalLayoutDown->indexOf(ui->grpBoxAED)==-1){ ui->horizontalLayoutUp->removeWidget(ui->grpBoxAED); ui->verticalLayoutDown->insertWidget(0,ui->grpBoxAED); } } QDialog::resizeEvent(event);
}@
Initially it works. But! According to start orientation of Pad after second or third rotation event resizeEvent does not occur and dialog does not resize rightly. I use Qt 5.3 for Android platform. Is it a BUG or my bad technique?
-
You are better off to handle the QEvent::OrientationChange rather on resize. I have not tried this even on Android though.
-
wrote on 23 Jun 2014, 12:13 last edited by
Dheerendra, thanks for advice.
I tested your variant. But there is not QEvent::OrientationChange event on Android. After rotation QEvent::Resize and QEvent::Paint occur only. -
wrote on 25 Jun 2014, 13:19 last edited by
I tried different variants of layout using with removeWidget, addWidget, insertWidget and trouble (stopping of resize event) occurs always. Perhaps it is BUG on layout reconstruction.
But! This problem (in my case) can be passed. I used QGridLayout, invisible pseudo widget and methods replaceWidget and addItem. Such set lets to do dynamic rebuilding of widgets location according to Pad orientation and problem is absent.
Simplisticly it looks like
@void ControlDialog::resizeEvent(QResizeEvent *event)
{ int iAED,row,col,row_sp,col_sp;//////// I do it because index of grpBoxAED (as occurred) can change //////////
iAED = ui->gridLayoutDynamic->indexOf(ui->grpBoxAED);
ui->gridLayoutDynamic->getItemPosition(iAED,&row,&col,&row_sp,&col_sp);
////////////////////////////////////////////////////////////////////////////////////////if(width()>height()){
if(row==1){
qDebug()<<"layout operation w>h";ui->gridLayoutDynamic->addItem(ui->gridLayoutDynamic->replaceWidget( ui->pseudoBox,ui->grpBoxAED),1,0,1,-1); ////no expanding (I did not find other way for changing of this property) ui->gridLayoutDynamic->addItem(ui->gridLayoutDynamic->replaceWidget( ui->grpBoxMED,ui->grpBoxMED),0,0,1,1); }
}
else{
if(row==0){
qDebug()<<"layout operation w<h";ui->gridLayoutDynamic->addItem(ui->gridLayoutDynamic->replaceWidget( ui->pseudoBox,ui->grpBoxAED),0,1,1,-1); /////for expanding (I did not find other way for changing of this property) ui->gridLayoutDynamic->addItem(ui->gridLayoutDynamic->replaceWidget( ui->grpBoxMED,ui->grpBoxMED),0,0,1,-1); }
}
QDialog::resizeEvent(event);
}@
-
wrote on 27 Jun 2014, 11:22 last edited by
Yesterday I updated Qt to 5.3.1 and found out that problem is not in layouts. In old Qt versions (5.2.1 and 5.3.0) on changing of Pad orientation Resize event came and I thought that so it must be (I have got small Qt experience). I did not use QSensor (QOrientationSensor, QOrientationReading). In new Qt 5.3.1 resize event does not come on orientation changing. It is right. And for monitoring of Pad orientation changing it needs to use QOrientationSensor and change dialog size by necessity.
I have found out I must publish these posts in "Mobile and Embedded":http://qt-project.org/forums/viewforum/11/ forum but I don't know how to replace this thread now. -
Hi,
Done :)
4/6