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. Manage the resizing of related widgets
Forum Updated to NodeBB v4.3 + New Features

Manage the resizing of related widgets

Scheduled Pinned Locked Moved General and Desktop
5 Posts 2 Posters 1.5k 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.
  • A Offline
    A Offline
    Alain38
    wrote on last edited by
    #1

    Hi,
    I have a simple problem that is the following:

    I have four widgets that are organized in a 2*2 matrix,

    the four widgets must have the same size and be squared,

    When I resize the window containing the widgets, they must resize themselves maintaining the second constraint, and without going outside the window.

    And now the question is "how can I do this?".

    I have tried by using QWidget::heightForWidth(int w) function, returning w each time. But, when I only resize in the x direction, the height becomes too large and the widgets go outside the window.

    I have tried putting the matrix in a widget and reimplement the resizeEvent() function of this widget. The resizeEvent() is set to compute the expected size of the widgets and to resize them. But in this case I have an infinite recursion and I see the widgets reducing their size and disappearing.

    I expected to replace the QWidget::resize() function. But this function is not virtual. Hence I will probably do not have the expected result.

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      it should be sufficient to listen to the resize event of the window correct?
      If so you could do something like this (NOT tested though, but it should give you an idea):
      @
      void MyWindow::resizeEvent(QResizeEvent* event)
      {
      BaseClass::resizeEvent(event);

      QSize newSize = event->size();
      QSize oldSize = event->oldSize();
      
      if( newSize.width() != oldSize.width() )
            this->resize( QSize(newSize.widht(),newSize.width() );
      else if( newSize.height() != oldSize.height() )
            this->resize( QSize(newSize.height(),newSize.height() );
      

      }
      @
      But this is rather dirty and maybe less ideal solution.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0
      • A Offline
        A Offline
        Alain38
        wrote on last edited by
        #3

        Hi,
        To try. But not in the window itself (do not have to be squared, and contain other elements). May be on a widget containing my matrix. But the aesthetic will probably be not really good. As other widgets will be placed as if the matrix took its full size.

        1 Reply Last reply
        0
        • raven-worxR Offline
          raven-worxR Offline
          raven-worx
          Moderators
          wrote on last edited by
          #4

          ok this makes the whole thing more tricky...but not impossible. ;)

          You can use "QSingleItemSquareLayout":http://developer.nokia.com/Community/Wiki/Archived:Maintaining_square_form_for_a_QWidget. Place you widget which is holding your 4 widgets in the 2x2 grid inside this layout. Then put the layout in your main window where you want it.

          --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
          If you have a question please use the forum so others can benefit from the solution in the future

          1 Reply Last reply
          0
          • A Offline
            A Offline
            Alain38
            wrote on last edited by
            #5

            Thanks for the link. I will probably not using QSingleItemSquareLayout. But it gives me an idea. Instead of subclassing QLayout I will subclass QWidgetItem by just overridding setGeometry (that is virtual).

            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