Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Qt Mdi Area get size not including scroll area
Forum Updated to NodeBB v4.3 + New Features

Qt Mdi Area get size not including scroll area

Scheduled Pinned Locked Moved Solved General and Desktop
4 Posts 2 Posters 587 Views 1 Watching
  • 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.
  • H Offline
    H Offline
    haris123
    wrote on 4 Jul 2022, 07:31 last edited by
    #1

    I have some issue with Qt MdiArea where I created a sub-window which fit inside MdiArea, and then I check the size of MdiArea got correct result. But if I move the window to the end of MdiArea which will make scroll bar appear, and check the MdiArea size again, but getting the same size as window without scrollbar. I think the scroll area not considering while getting size, but only the viewport size returning.

    How I can get the total size including scrollable area of the MdiArea.

    MainWindow::MainWindow(QWidget *parent)
        : QMainWindow(parent)
        , ui(new Ui::MainWindow)
    {
        ui->setupUi(this);
        ui->mdiArea->setHorizontalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        ui->mdiArea->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded);
        ui->mdiArea->setOption(QMdiArea::DontMaximizeSubWindowOnActivation);
    
        // Set Mdi Area as the central widget
        setCentralWidget(ui->mdiArea);
    
    
        QWidget *widget = new QWidget(ui->mdiArea);
        QMdiSubWindow *w1 = ui->mdiArea->addSubWindow(widget);
        w1->resize(320, 240);
        // And show the widget
        widget->show();
    }
    
    
    void MainWindow::wheelEvent(QWheelEvent *event)
    {
        qDebug()<<"mdiArea size: "<<ui->mdiArea->size();
    
    
    }
    

    Correct Result without scroll bar.
    alt text

    Wrong Result with scroll bar.
    alt text

    1 Reply Last reply
    0
    • C Offline
      C Offline
      Chris Kawa
      Lifetime Qt Champion
      wrote on 4 Jul 2022, 18:19 last edited by
      #2

      ui->mdiArea->size() is the size of the entire widget, including all its children and scrollbars are just children.
      What you probably want is the size of the scroll area viewport - the widget that hosts the actual contents of the area, so ui->mdiArea->viewport()->size().

      1 Reply Last reply
      0
      • H Offline
        H Offline
        haris123
        wrote on 5 Jul 2022, 07:29 last edited by haris123 7 May 2022, 07:29
        #3

        @Chris-Kawa said in Qt Mdi Area get size not including scroll area:

        ui->mdiArea->viewport()->size()

        I tried that too, but got the same result.

        qDebug()<<"mdiArea size: "<<ui->mdiArea->size();
        qDebug()<<"mdiArea -> viewport size: "<<ui->mdiArea->viewport()->size();
        

        Print the same result when scroll bar there and not there.

        mdiArea size: QSize(982, 662)
        mdiArea -> viewport size: QSize(982, 645)

        And I got it solved by,

           QScrollBar  *h_bar = ui->mdiArea->horizontalScrollBar();
           QScrollBar  *v_bar = ui->mdiArea->verticalScrollBar();
        
           int total_width = h_bar->maximum()-h_bar->minimum()+ui->mdiArea->width();
           int total_height = v_bar->maximum()-v_bar->minimum()+ui->mdiArea->height();
        

        Seems working for me.

        1 Reply Last reply
        0
        • C Offline
          C Offline
          Chris Kawa
          Lifetime Qt Champion
          wrote on 5 Jul 2022, 08:57 last edited by
          #4

          Oh, I misunderstood what you want. I thought you wanted the viewport size but you want the actual viewport contents size. QScrollArea has a widget() method that lets you get the content widget and its size, but unfortunately QMdiArea doesn't seem to have similar option, so your solution might be ok.

          1 Reply Last reply
          1

          1/4

          4 Jul 2022, 07:31

          • Login

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