PDA

View Full Version : QWidget::update does not work!



sapali
16th March 2011, 23:34
Hello,

I am trying to update the widget after inserting new qsliders, but it does not update the widget and the slideer does not apear!! I am using qt 3 btw. Any suggestions?

stampede
17th March 2011, 00:10
Any suggestions?
Post the code.

sapali
17th March 2011, 00:28
Here is the part of the code where I am trying to update:


void winfold(){
setUpdatesEnabled( FALSE );

QSlider *ang = new QSlider(0, 180, 1, 0, Qt::Horizontal, sliderBox, "angle");
emit(whichindex(sliders.size()));
connect(this, SIGNAL(whichindex(int)), glwidget, SLOT(set_index(int)));
connect(ang, SIGNAL(valueChanged(int)),this, SLOT(set_ang(int)));
sliders.push_back(ang);

glwidget->fold_sync();
// QWidget::update();
cout<<isVisible()<<endl;
setUpdatesEnabled( TRUE );
// repaint();
update();
cout<<"I UPDATED THE WINDOW!! "<<sliders.size()<<endl;


}

stampede
17th March 2011, 00:52
Ok, but in order to display the slider, you'll need to add it to widget's layout. Only thing I see is that you push the slider into some list, are the elements added to layout later ?

sapali
17th March 2011, 01:03
I have done this in my Window constructor:

QHBoxLayout* mainLayout = new QHBoxLayout( this, 20, 20, "mainLayout");
mainLayout->addWidget( sliderBox );

I have already done this in my Window constructor:

QHBoxLayout* mainLayout = new QHBoxLayout( this, 20, 20, "mainLayout");
mainLayout->addWidget( sliderBox );

Isn't this enough?

ChrisW67
17th March 2011, 01:43
Clearly not. Your constructor adds "sliderBox" to a layout that we can only assume you apply as Window's layout.

You then create a new QSlider that I assume you wish to become part of the "sliderBox" widget's display. You need to add the new QSlider widget you create to the existing layout of "sliderBox" (not the main window). We have no details of "sliderBox".

What class does winfold() belong to?

Please use
and tags around your code.

sapali
17th March 2011, 07:18
Well, I have a window class and the winfold() is a slot in my window.h, the point is that this sliders are shown up if I do the same thing in the constructor of my Window class, and I thought that by
QSlider *ang = new QSlider(0, 180, 1, 0, Qt::Horizontal, sliderBox, "angle");
it would add it to the sliderBox as well, as it is doing so when I do the same thing in constructor... and I could not find any method in QHBox for adding an object to it. That's why I was led to believe that problem is from update(). ?

Thank you

stampede
17th March 2011, 08:35
QHboxLayout is a subclass of QLayout, so you can use any method that QLayout has, for example QLayout::addWidget (http://doc.qt.nokia.com/latest/qlayout.html#addWidget)

sapali
17th March 2011, 17:56
Thanks a lot for your help.
It works now. I just added
ang->show() because the isVisible() used to return false