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. Maximize widget upon main window maximize [Solved]
QtWS25 Last Chance

Maximize widget upon main window maximize [Solved]

Scheduled Pinned Locked Moved General and Desktop
7 Posts 4 Posters 8.4k 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.
  • Z Offline
    Z Offline
    zvivered
    wrote on last edited by
    #1

    Hello,

    I have one widget (tree) in the main window.

    I want that it will always be maximixed to the size of the main window when the main window is resized (and upon application launch).
    Can you help ?

    Thanks,
    Zvika

    [edit: fixed typo in title. eddy]

    1 Reply Last reply
    0
    • EddyE Offline
      EddyE Offline
      Eddy
      wrote on last edited by
      #2

      You probably didn't use "a layout":http://qt-project.org/doc/qt-4.7/layout.html

      Qt Certified Specialist
      www.edalsolutions.be

      1 Reply Last reply
      0
      • Z Offline
        Z Offline
        zvivered
        wrote on last edited by
        #3

        Dear Eddy,

        I wrote the following code:
        @
        MainWindow::MainWindow(QWidget *parent) :
        QMainWindow(parent),
        ui(new Ui::MainWindow)
        {
        ui->setupUi(this);

        QHBoxLayout *mainLayout = new QHBoxLayout;
        mainLayout->addWidget(ui->treeWidget);
        setLayout(mainLayout);
        

        }
        @
        But the tree widget is not resized upon window resize.

        Can you help ?
        Thanks,
        Zvika.

        [edit: please add @code tags around your code next time. It makes it easier to read for us, eddy]

        1 Reply Last reply
        0
        • EddyE Offline
          EddyE Offline
          Eddy
          wrote on last edited by
          #4

          At first sight your code looks ok. Are you saying that your border of the treeWidget is not following the size or the contents of the treeWidget don't behave as expected?

          [Edit maybe "resizeColumnToContents.":http://qt-project.org/doc/qt-4.8/qtreeview.html#resizeColumnToContents
          Is what you need]

          Qt Certified Specialist
          www.edalsolutions.be

          1 Reply Last reply
          0
          • D Offline
            D Offline
            dbzhang800
            wrote on last edited by
            #5

            No, the code is wrong.

            @
            setLayout(mainLayout)
            @

            will failed here, as QMainWindow already has a Layout. (Otherwise, how can QMenuBar, QStatusBar and QToolBar s work?)

            You don't need to write such code, just put QTreeWidget to your central Widget, then apply a layout for it. All this can be done in Designer.

            1 Reply Last reply
            0
            • Z Offline
              Z Offline
              zvivered
              wrote on last edited by
              #6

              Dear Members,

              I did it with the designer.
              It works fine.

              Thanks,
              Zvika.

              1 Reply Last reply
              0
              • M Offline
                M Offline
                mlong
                wrote on last edited by
                #7

                Please be sure and edit your original post and add [Solved] to the title. Thanks!

                Software Engineer
                My views and opinions do not necessarily reflect those of anyone -- living or dead, real or fictional -- in this universe or any other similar multiverse node. Void where prohibited. Your mileage may vary. Caveat emptor.

                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