PDA

View Full Version : Resizing Issues



Jtjr008
7th June 2012, 15:39
First, is there a good source on how the resizing systems works in Qt? If I had better understood how it works I may be better able to understand my problems.

Basically, I have a slider and want to align a label underneath. I use a spacer to move the label to underneath the slider handle. See picture.

7815

I overrode the resizeEvent and replaced it with the following code:



void ColorMapWidget::resizeEvent(QResizeEvent *e)
{
Q_UNUSED(e);
int val = slider->value();
double spacing = slider->width() * (val / 10000.0) - (val / 10000.0) * (centerSlidingFrame->width() + 1);
sliderInfoSpacer->changeSize((int)spacing, 0, QSizePolicy::Fixed, QSizePolicy::Fixed);

qDebug() << slider->width() << spacing;
}



My first problem involves incorrect sizes in the resizeEvent. The output looks like:

[Thu 10:14:56:066 0x430] INFO: 640 269.5
[Thu 10:15:04:835 0x430] INFO: 309 134.5
[Thu 10:15:04:867 0x430] INFO: 310 135

Where the first value is the initial "size" after construction and the later are after I manually drag the corner of the widget to resize it. Obviously there is a large discrepancy between what it thinks the size is and what the actual size is at startup. I have a similar issue with another class where I have subclassed a QwtPlot and resize the symbols on it based on the size in the resizeEvent. The initial size is always off but subsequent resizes are correct.

My second issues stems from updating the size of the spacer. The spacer is not being updated or redrawn (correctly) after the resizeEvent. When I reset the style sheet for the color map the spacer will resize and move to underneath the slider handle. On resizeEvents it does not update though. Am I missing something so that the spacer is actually updated? I've tried invalidating the layout and the widget, calling adjustSize(), and few others. From my understanding it should get a repaint() call right after the resizeEvent. Every other widget scales except for the spacer.

Thanks.

Jtjr008
12th June 2012, 15:30
So, I fixed the updating issue. It appears it only changes size when you invalidate the layout the QSpacerItem was added to (I was invalidating the entire widgets layout). No one has any ideas on why the initial size is so off?