Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Mobile and Embedded
  4. [SOLVED]Is it a BUG or bad technique?
QtWS25 Last Chance

[SOLVED]Is it a BUG or bad technique?

Scheduled Pinned Locked Moved Mobile and Embedded
6 Posts 3 Posters 2.1k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • V Offline
    V Offline
    vladimir70
    wrote on last edited by
    #1

    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?

    1 Reply Last reply
    0
    • dheerendraD Offline
      dheerendraD Offline
      dheerendra
      Qt Champions 2022
      wrote on last edited by
      #2

      You are better off to handle the QEvent::OrientationChange rather on resize. I have not tried this even on Android though.

      Dheerendra
      @Community Service
      Certified Qt Specialist
      http://www.pthinks.com

      1 Reply Last reply
      0
      • V Offline
        V Offline
        vladimir70
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • V Offline
          V Offline
          vladimir70
          wrote on last edited by
          #4

          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);
          

          }@

          1 Reply Last reply
          0
          • V Offline
            V Offline
            vladimir70
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Done :)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved