Results 1 to 3 of 3

Thread: Set initial size of widget (not min or max)

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Apr 2010
    Posts
    17
    Qt products
    Qt4
    Platforms
    Windows

    Default Set initial size of widget (not min or max)

    I have a graphical application whose main window extends qwidget. Here's how it works:

    • borderPanel is a 2x1 GridPanel. Top row contains buttons / sliders / labels and only expands horizontally. Bottom row contains everything else and expands in both directions.
    • gridPanel is a 2x3 GridPanel. These expand in either direction. This panel goes in the bottom row of borderlPanel.
    • border is a 2x1 GridPanel. The bottom row only expands horizontally and contains 3 QLabels. The top row expands in both directions and contains everything else. One borderPanel goes in each grid of gridPanel.
    • window is an ArrayWindow extends QWidget and draws an array. One of each goes in the top row of each border.

    All the panels are created and placed in the constructor except the ArrayWindows. This is handled by this method:

    Qt Code:
    1. void SortWindow::populate(int** d, int s, QString* n[]) {
    2. size = s;
    3. for (int i=0; i<6; i++) {
    4. name[i]->setText(" "+QString::number(i+1)+": "+*n[i]);
    5. window[i] = new ArrayWindow(this, d[i], s, s+2, s+2);
    6. // window[i]->updateGeometry();
    7. // window[i]->resize(s+2,s+2);
    8. // window[i]->setGeometry(0,0,s+2,s+2);
    9. border[i]->addWidget(window[i],0,0);
    10. }
    11. // borderPanel->invalidate();
    12. }
    To copy to clipboard, switch view to plain text mode 
    d is an array of int arrays, s is the length of each array, n is an array of names for name QLabels in the borderPanels. Commented out are some attempts I made that didn't work. In all cases, the size was based on the width the QLabels in the bottom row of the borderPanels and is way too small with s=300. In ArrayWindow I also reimplemented sizehint as so:

    Qt Code:
    1. public:
    2. virtual QSize sizeHint() const;
    To copy to clipboard, switch view to plain text mode 
    Qt Code:
    1. QSize ArrayWindow::sizeHint() const {
    2. return QSize(width, height);
    3. }
    To copy to clipboard, switch view to plain text mode 
    What did work was setMinimumSize, but the problem is this application supports resizing the screen. The user resizes the window, which recenters the content and enables a button, you click the button and new arrays are generated that best fit the new window size. This works for both increasing and decreasing the window size, so locking it to some minimum is undesirable.

    thanks
    Last edited by Galen; 15th April 2010 at 06:22.

Similar Threads

  1. initial size of widgets in a QSplitter
    By momesana in forum Newbie
    Replies: 3
    Last Post: 12th July 2012, 15:41
  2. Replies: 4
    Last Post: 11th July 2010, 09:47
  3. Adjust the initial size of a QTextEdit in a layout
    By hecinho in forum Qt Programming
    Replies: 0
    Last Post: 26th November 2009, 15:58
  4. QGraphicsView wrong initial size of objects
    By syrtyr in forum Qt Programming
    Replies: 2
    Last Post: 14th July 2009, 07:13
  5. How to set initial QDockWidget's size?
    By rajesh in forum Qt Programming
    Replies: 4
    Last Post: 16th November 2006, 15:49

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.