[Solved]QSplitter Animation
-
wrote on 27 Jun 2013, 07:05 last edited by
Hello,
I get some issue with QSplitter. I have two widgets and I hide one of those by:
@QList<int> l_sizes;
l_sizes << width() << 0;
MySplitter->setSizes(l_sizes);@Now I'd like to show the hide one by expand that widget, I have tried QPropertyAnimation, but nothing happened. Could anyone help me with the problem?
Thanks a lot!!
Solution:
Use a QTimeLine to change the QList<int>, and then set it. -
[quote author="Saki" date="1372316713"]Now I'd like to show the hide one by expand that widget, I have tried QPropertyAnimation, but nothing happened. Could anyone help me with the problem?[/quote]
Not with the information provided...Please post the code for your property animation and your class which you want to animate.
-
wrote on 27 Jun 2013, 09:04 last edited by
[quote author="raven-worx" date="1372317644"][quote author="Saki" date="1372316713"]Now I'd like to show the hide one by expand that widget, I have tried QPropertyAnimation, but nothing happened. Could anyone help me with the problem?[/quote]
Not with the information provided...Please post the code for your property animation and your class which you want to animate.
[/quote]
I'm so sorry I forget it...Here is my code:
@kcicompiledock::kcicompiledock(QWidget *parent):
QDockWidget(parent)
{
//Set Object Name.
setObjectName(QString("Compile Dock"));//Set Dock Style. setContentsMargins(0,0,0,0); QPalette pal=this->palette(); //pal.setColor(QPalette::Base,QColor(0x35,0x35,0x35)); pal.setColor(QPalette::Base,QColor(0x35,0x35,0x35)); pal.setColor(QPalette::WindowText,QColor(255,255,255)); pal.setColor(QPalette::Button,QColor(83,83,83)); pal.setColor(QPalette::Text,QColor(255,255,255)); pal.setColor(QPalette::ButtonText,QColor(255,255,255)); this->setPalette(pal); setWindowTitle(QString(tr("Compiler"))); setAllowedAreas(Qt::BottomDockWidgetArea); //Set Dock Widget and Layout. //objCombine=new QWidget(this); //objCombine->setContentsMargins(0,0,0,0); splCombine=new QSplitter(Qt::Horizontal, this); splCombine->setContentsMargins(0,0,0,0); //Set Text Output. compileOutput=new QPlainTextEdit(this); compileOutput->setContentsMargins(0,0,0,0); compileOutput->setWordWrapMode(QTextOption::NoWrap); splCombine->addWidget(compileOutput); //Set TreeView Controls. trevwCompileInfo=new QTreeView(this); trevwCompileInfo->setContentsMargins(0,0,0,0); pal=trevwCompileInfo->palette(); pal.setColor(QPalette::Foreground,QColor(255,255,255)); trevwCompileInfo->setPalette(pal); compileInfo=new QStandardItemModel(); trevwCompileInfo->setGeometry(0,0,0,0); splCombine->addWidget(trevwCompileInfo); QList<int> l_sizes; l_sizes << width() << 0; splCombine->setSizes(l_sizes); setWidget(splCombine);
}
void kcicompiledock::animeShowError()
{
QPropertyAnimation showTrevwAnime(trevwCompileInfo,"geometry");
QRect startRect=trevwCompileInfo->rect();
QRect finalRect=startRect;
finalRect.setWidth(100);
showTrevwAnime.setStartValue(startRect);
showTrevwAnime.setEndValue(finalRect);showTrevwAnime.start();
}@
I'd like to animate the QTreeView object, like the code in animeShowError. But I know this code didn't work at all. I don't know how to animate the widget.
-
i don't see any QPropertyAnimation in your code?!
-
wrote on 27 Jun 2013, 14:54 last edited by
[quote author="raven-worx" date="1372326854"]i don't see any QPropertyAnimation in your code?![/quote]
Please see LINE #50.
-
your animation doesn't work because you create the animation object on the stack...thus it is destroyed right after the method is exited.
so you should do this instead:
@
void kcicompiledock::animeShowError()
{
QPropertyAnimation* showTrevwAnime = new QPropertyAnimation(trevwCompileInfo,"geometry");
QRect startRect=trevwCompileInfo->rect();
QRect finalRect=startRect;
finalRect.setWidth(100);
showTrevwAnime->setStartValue(startRect);
showTrevwAnime->setEndValue(finalRect);showTrevwAnime->start(QAbstractAnimation::DeleteWhenStopped);
}
@ -
wrote on 27 Jun 2013, 23:14 last edited by
[quote author="raven-worx" date="1372348188"]your animation doesn't work because you create the animation object on the stack...thus it is destroyed right after the method is exited.
so you should do this instead:
@
void kcicompiledock::animeShowError()
{
QPropertyAnimation* showTrevwAnime = new QPropertyAnimation(trevwCompileInfo,"geometry");
QRect startRect=trevwCompileInfo->rect();
QRect finalRect=startRect;
finalRect.setWidth(100);
showTrevwAnime->setStartValue(startRect);
showTrevwAnime->setEndValue(finalRect);showTrevwAnime->start(QAbstractAnimation::DeleteWhenStopped);
}
@[/quote]Thanks, but...is this the reason?! I can't believe it! I think I should change the object to the Parent Object(DockWidget), and change the property "geometry" into another. I'll try the code later.
BTW: I'd like to know more about your code. Mine is just let the TreeView invisible. Why just destroy it when it stop will work? Shouldn't we change the size of one of the part of the dock? -
sure thats the reason... the animation can only work when there is a object which controls the animation. When the animation object is destroyed there is no animation.
The DeleteWhenStopped argument is necessary to avoid memory leaks, since you don't hold a reference anywhere to delete it once it is finished. -
wrote on 28 Jun 2013, 10:52 last edited by
[quote author="raven-worx" date="1372400678"]sure thats the reason... the animation can only work when there is a object which controls the animation. When the animation object is destroyed there is no animation.
The DeleteWhenStopped argument is necessary to avoid memory leaks, since you don't hold a reference anywhere to delete it once it is finished.[/quote]I'm so sorry that this didn't work. I think that we shouldn't just change the geometry of TreeView. We should change the width of Dock's child window instead.
-
wrote on 29 Jun 2013, 12:16 last edited by
Well, no one knows anything about this?
-
wrote on 30 Jun 2013, 11:31 last edited by
All Right, It seems that I have to solve this problem by myself. Thanks for everyone.
-
wrote on 23 Jul 2013, 11:04 last edited by
Hi, For animating QSplitter you have to have a animation on a property of QSplitter not on property of its child widgets. so as the QSplitter has no property for sizes so you have to create that property by yourself and animate through it. (Try it to change splitter position without animation at first and then add animation on that property)
-
wrote on 11 Aug 2013, 05:51 last edited by
[quote author="Mostafa Alizadeh" date="1374577477"]Hi, For animating QSplitter you have to have a animation on a property of QSplitter not on property of its child widgets. so as the QSplitter has no property for sizes so you have to create that property by yourself and animate through it. (Try it to change splitter position without animation at first and then add animation on that property)[/quote]
Thanks a million, and I solved it by using QTimeLine. This is not relate to the DeleteWhenStopped, right?