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. How to check for window size changes?
Forum Updated to NodeBB v4.3 + New Features

How to check for window size changes?

Scheduled Pinned Locked Moved Solved General and Desktop
3 Posts 2 Posters 2.3k 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.
  • L Offline
    L Offline
    legitnameyo
    wrote on last edited by
    #1

    There are a number of tasks that I want to execute if the window size changes, is there a way to execute code when that happens? I've read some stuff on QResizeEvent but when functions get involved they usually involve passing a QResizeEvent to the function, which I do not know how to do. Is there a way with QResizeEvent or do I need to use something else in order to detect and execute code when the mainwindow size changes?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      legitnameyo
      wrote on last edited by legitnameyo
      #2

      The code I came up with is:

      void MainWindow::resizeEvent(QResizeEvent *e) {
          int window_height = MainWindow::size().height();
          int window_width = MainWindow::size().width();
      
          ui->home_frame->resize(window_width, 110);
          ui->tab->resize(window_width, 110);
      }
      

      which doesn't resize the frame at all... Any idea why it doesn't do that? I managed to resize a QTextEdit, so I know it works now, but I can't seem to resize the frame or the tab.

      Edit:

      ui->tabWidget->resize(window_width, 100);
      

      fixed it!

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

        Hi,

        Just in case, QResizeEvent gives you the new size of the widget.

        Out of curiosity, why are you doing resizing by hand rather than use a layout ?

        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
        1

        • Login

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