[Qt-interest] QLayout Disaster (resizing)
Paul England
pengland at cmt-asia.com
Tue Jul 14 02:13:03 CEST 2009
This is driving me nuts, so before I tinker any more I should make sure
what I'm trying to achieve is even possible.
My application is a QDialog, which has quite a few nested
QHBoxLayouts/QVBoxLayouts and other QWidgets (QPushButtons, QLineEdits,
and QTableWidgetItems for the most part).
I set all of my Layouts to sizeConstraint to QLayout::SetFixedSize, and
I put in an stretch of -1. The stretch works perfectly. If the GUI is
resized to anything larger than the necessary space, everything stays
positioned (in the top left-hand corner). However, when the GUI is
resized to something smaller, the view_layout is definitely resized.
Each my_view_t within it keeps it's relative position (all of the
widgets within it keep their relative spacing and sizng) but they will
overlap with each other. So, if I have a QTableWidget within each
my_view_t, if I resize the GUI small enough, I have 3 QTableWidgets
overlapping one another. This is obviously bad, and I can't figure out
exactly where I'm messing it up. The desired effect would be that the
GUI simply resizes, but all the widgets inside are of a static size. If
the user only wants to "see" one of the my_view_t's, he just resizes the
window to the desired size.
Here's some very summed up code.
my_view_t::my_view_t() : public QHBoxLayout
{
/* Add widgets & other layouts into this */
setSizeConstraint( QLayout::SetFixedSize );
}
my_dialog_t::my_dialog_t() : public QDialog
{
QVBoxLayout* main_layout = new QVBoxLayout( this );
QHBoxLayout* view_layout = new QHBoxLayout( this );
for ( int i = 0; i < 3; i++ ) {
my_view_t* my_view = new my_view_t();
view_layout->addLayout( my_view_t );
}
view_layout->insertStretch( -1, 0 );
view_layout->setSizeConstraint( QLayout::SetFixedSize );
main_layout->insertStretch( -1, 0 );
setLayout( main_layout );
}
More information about the Qt-interest-old
mailing list