[solved] QMovie (with animated GIF) in QTreeWidget



  • Hi,

    I'd like to insert a QMovie with an animated GIF in a QTreeWidget, in order to show some states and process of my application.

    I already searched but I didn't find any clear response or example.

    I'd really appreciate if you could help me. Thanks!

    Best regards.



  • Hi you can have a look on this "topic":http://qt-project.org/forums/viewthread/16800/



  • [quote author="Sam" date="1348131695"]Hi you can have a look on this "topic":http://qt-project.org/forums/viewthread/16800/[/quote]

    Thank you Sam, I usually use that code for a "normal" use of QMovie and Gifs:

    @QMovie *movie = new QMovie(":Animations/icons/yourAnimatedIcon.gif");
    QLabel *yourLabel = new QLabel(this);
    yourLabel->setMovie(movie);
    movie->start();@

    So the next step is config a custom delegate and adding to a QTreeWidget Item. How can I do it in a simple and efficient way?

    I will post the complete solution to the initial question for the future users.

    Thank you!



  • Take a look at QTreeWidget::setItemWidget(), and set you label on the item that way. No need to deal with delegates. Delegates are not really suitable to display widgets for items that are not in edit mode.



  • Yes I Agree with Andre , no need to deal with delegates, you can simply use QTreeWidget::setItemWidget().

    I'll update my other post as well.



  • [quote author="Andre" date="1348133894"]Take a look at QTreeWidget::setItemWidget(), and set you label on the item that way. No need to deal with delegates. Delegates are not really suitable to display widgets for items that are not in edit mode.[/quote]

    Thank you!! it works!

    I finally use QTreeWidget::setItemWidget() as follow:

    @//Create a tree:
    QTreeWidget *myTree = new QTreeWidget(parentWidget);

    //Create a tree item child:
    QTreeWidgetItem *item = new TreeWidgetItem(myTree);

    //Create my custom widget. It contains a QLabel with a QMovie (Gif)
    MyCustomWidget *myWidget = new MyCustomWidget(parent,pathGif);

    //Set to tree item child:
    myTree->setItemWidget(myWidget,0,item);

    //Connect signals and slot for control movie
    connect(...);@

    For MyCustomWidget, I used a Qt designer form class. I configured the layout geometry in my .ui in order to fit with the height row, and placed there the QLabel that will contain the QMovie.

    The QMovie is created and linked to QLabel in the constructor of MyCustomWidget, which has slots for receiving signals and controlling the qmovie GIF.

    The result is this (more or less):

    !http://s17.postimage.org/bop2csl3j/result_QTree_QWidget_QMovie_Gif.png(result qmovie gif in qtreewidget)!


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.