Results 1 to 18 of 18

Thread: qwidget into QML

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default qwidget into QML

    hi all,

    I'm trying to put a treeview in my QML application.
    The last thing i was trying was to put a qwidget (QTreewidget) into my QML file.
    so i used qmlRegisterType, and have :

    javascript Code:
    1. import QtQuick 1.0
    2. import Test 1.0
    3.  
    4. Rectangle {
    5. id:ttt
    6. width: 360
    7. height: 360
    8. CustomTree{
    9. id:customW
    10. parent:ttt
    11. // anchors.fill: parent
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    as my QML file but nothing happens
    can someone help me ?
    Last edited by wysota; 15th August 2011 at 14:52. Reason: missing [code] tags

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qwidget into QML

    Did you implement a subclass of QDeclarativeItem for yout widget?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qwidget into QML

    this is the part i'm not sure of
    i create an object subclassed from QDeclarativeItem with
    this->setFlag(QGraphicsItem::ItemHasNoContents, false);

    my problem is how to paint it. I'm not familiar with the paint() function

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qwidget into QML

    I don't see your point. In my opinion your declarative item should create a tree view, a proxy item for it and set that item as the child of the declarative item. Then you can forward all calls you want from the item to the widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qwidget into QML

    i must be really @#?! or tired
    when i try this
    Qt Code:
    1. CustomWidget::CustomWidget(QDeclarativeItem *parent) :
    2. QDeclarativeItem(parent)
    3. {
    4. this->setFlag(QGraphicsItem::ItemHasNoContents, false);
    5.  
    6. tree = new QTreeWidget;
    7. new QTreeWidgetItem(tree, QStringList()<<"First");
    8. new QTreeWidgetItem(tree, QStringList()<<"Second");
    9. new QTreeWidgetItem(tree, QStringList()<<"Third");
    10. new QTreeWidgetItem(tree, QStringList()<<"Fourth");
    11.  
    12. proxy = new QGraphicsProxyWidget;
    13. proxy->setWidget(tree);
    14. proxy->setParentItem(this);
    15.  
    16.  
    17. }
    To copy to clipboard, switch view to plain text mode 

    in the constructor of my QDeclarativeItem it doesn't display anything

    here is the qml file

    Qt Code:
    1. import QtQuick 1.0
    2. import Test 1.0
    3.  
    4. Rectangle {
    5. id:ttt
    6. width: 360
    7. height: 360
    8. CustomTree{
    9. id:customW
    10. anchors.fill:parent
    11. }
    12. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qwidget into QML

    This works for me:
    Qt Code:
    1. #include <QtDeclarative>
    2. #include <QtGui>
    3.  
    4. class PushButtonItem : public QDeclarativeItem {
    5. Q_OBJECT
    6. public:
    7. PushButtonItem(QDeclarativeItem *parent =0) : QDeclarativeItem(parent) {
    8. pb = new QPushButton("text");
    9. proxy = new QGraphicsProxyWidget(this);
    10. proxy->setWidget(pb);
    11. proxy->setPos(-pb->sizeHint().width()/2, -pb->sizeHint().height()/2);
    12. }
    13. private:
    14. QGraphicsProxyWidget *proxy;
    15. };
    16.  
    17.  
    18. #include "main.moc"
    19.  
    20. int main(int argc, char **argv) {
    21. QApplication app(argc, argv);
    22. QDeclarativeView view;
    23. qmlRegisterType<PushButtonItem>("PushButton", 1, 0, "PushButtonItem");
    24. view.setSource(QUrl::fromLocalFile("file.qml"));
    25. view.show();
    26. return app.exec();
    27. };
    To copy to clipboard, switch view to plain text mode 

    with file.qml:
    javascript Code:
    1. import Qt 4.7
    2. import PushButton 1.0
    3.  
    4.  
    5. Rectangle {
    6. width: 300
    7. height: 300
    8. PushButtonItem {
    9. anchors.centerIn: parent
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qwidget into QML

    i had a strange case mismatch warning that i didn't see

    anyway, thanks to you i understand it much better

    thank you

  8. #8
    Join Date
    Nov 2010
    Posts
    82
    Thanked 9 Times in 9 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: qwidget into QML

    I discovered that you can directly subclass QGraphicsProxyWidget and that works even better for resizing and positioning with QML

  9. #9
    Join Date
    Mar 2011
    Location
    united states
    Posts
    1
    Qt products
    PyQt3 PyQt4
    Platforms
    MacOS X

    Default Re: qwidget into QML

    the code of third snippet does not understand.

  10. #10

    Default Re: qwidget into QML

    Hi,

    I used the same way to try to embedded a QX11EmbedContainer into QML but the result is not really good :
    My goal is to use the QX11EmbedContainer to execute mplayer and to declare this one as a QML Element to be able to manipulate it into my *.qml files.
    The result is, when I execute it, the video is played on a new window and not on my QML window.

    Here is the code :

    Qt Code:
    1. /* videodisplayitem.h */
    2.  
    3. #include <QDeclarativeItem>
    4. #include <QX11EmbedContainer>
    5. #include <QtDeclarative>
    6. #include <QProcess>
    7. #include <QtGui>
    8.  
    9. class VideoDisplayItem : public QDeclarativeItem
    10. {
    11. Q_OBJECT
    12. public:
    13. VideoDisplayItem(QDeclarativeItem *parent =0) : QDeclarativeItem(parent) {
    14. container = new QX11EmbedContainer(NULL);
    15.  
    16. // if I execute container->show(); here, I get the video on a new window
    17. container->show();
    18.  
    19. QProcess * process = new QProcess(container);
    20. QString executable("/usr/bin/mplayer");
    21. QStringList arguments;
    22. arguments << "-wid";
    23. arguments << QString::number(container->winId());
    24. arguments << "/myvideo.mp4";
    25. process->start(executable, arguments);
    26.  
    27. proxy = new QGraphicsProxyWidget(this);
    28. proxy->setWidget(container);
    29. proxy->setPos(-container->sizeHint().width()/2, -container->sizeHint().height()/2);
    30.  
    31. // if I execute container->show(); here, I get nothing visible
    32. // container->show();
    33. }
    34. private:
    35. QX11EmbedContainer *container;
    36. QGraphicsProxyWidget *proxy;
    37.  
    38. };
    To copy to clipboard, switch view to plain text mode 


    Qt Code:
    1. /* main.cpp */
    2.  
    3. #include <QtGui/QApplication>
    4. #include "videodisplayitem.h"
    5.  
    6. int main(int argc, char *argv[])
    7. {
    8. QApplication app(argc, argv);
    9. QDeclarativeView view;
    10. qmlRegisterType<VideoDisplayItem>("VideoDisplay", 1, 0, "VideoDisplayItem");
    11. view.setSource(QUrl::fromLocalFile("file.qml"));
    12. view.show();
    13. return app.exec();
    14. }
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. /* file.qml */
    2.  
    3. import Qt 4.7
    4. import VideoDisplay 1.0
    5.  
    6. Rectangle {
    7. width: 300
    8. height: 300
    9.  
    10. VideoDisplayItem {
    11. anchors.centerIn: parent
    12. }
    13. }
    To copy to clipboard, switch view to plain text mode 

    If you get any idea or advise, thanks for all.
    My way to proceed might be totally wrong but I dont have any other ideas how to do.

    Thanks for all.

  11. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: qwidget into QML

    It won't work with Embed. Use appropriate API from QtMultimedia instead.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


Similar Threads

  1. Replies: 1
    Last Post: 30th October 2010, 12:28
  2. Replies: 1
    Last Post: 16th September 2010, 15:57
  3. Replies: 1
    Last Post: 12th April 2010, 12:55
  4. Replies: 3
    Last Post: 1st April 2010, 23:56
  5. Replies: 1
    Last Post: 2nd May 2006, 21:11

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.