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:
void SortWindow
::populate(int** d,
int s,
QString* n
[]) { size = s;
for (int i=0; i<6; i++) {
name
[i
]->setText
(" "+QString::number(i
+1)+": "+*n
[i
]);
window[i] = new ArrayWindow(this, d[i], s, s+2, s+2);
// window[i]->updateGeometry();
// window[i]->resize(s+2,s+2);
// window[i]->setGeometry(0,0,s+2,s+2);
border[i]->addWidget(window[i],0,0);
}
// borderPanel->invalidate();
}
void SortWindow::populate(int** d, int s, QString* n[]) {
size = s;
for (int i=0; i<6; i++) {
name[i]->setText(" "+QString::number(i+1)+": "+*n[i]);
window[i] = new ArrayWindow(this, d[i], s, s+2, s+2);
// window[i]->updateGeometry();
// window[i]->resize(s+2,s+2);
// window[i]->setGeometry(0,0,s+2,s+2);
border[i]->addWidget(window[i],0,0);
}
// borderPanel->invalidate();
}
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:
public:
virtual QSize sizeHint
() const;
public:
virtual QSize sizeHint() const;
To copy to clipboard, switch view to plain text mode
QSize ArrayWindow
::sizeHint() const { return QSize(width, height
);
}
QSize ArrayWindow::sizeHint() const {
return QSize(width, height);
}
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
Bookmarks