Results 1 to 9 of 9

Thread: The problem when add QAxWidget into graphicsView.

  1. #1
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post

    Unhappy The problem when add QAxWidget into graphicsView.

    Hi, all.
    I want to show a MS Word document in a graphicsView, so I add a QAxWidget into the graphicsView,it indeed add the QAxWidget in. BUT the Word document doesn't show. I can't find the problem. Is there anybody knows how to show a Word document in the QAxWidget which is part of graphicsView? Any idea is welcomed. please.
    The following is my code:
    You should add
    CONFIG += qaxcontainer
    into the pro file .

    //main.cpp

    Qt Code:
    1. #include <QtGui/QApplication>
    2. #include "mainwindow.h"
    3. #include <QWidget>
    4. #include <QVBoxLayout>
    5. #include <QGraphicsScene>
    6. #include <QGraphicsView>
    7. #include <QLineEdit>
    8. #include <QGraphicsProxyWidget>
    9. #include <QSlider>
    10. #include <QLabel>
    11. #include <QAxWidget>
    12.  
    13.  
    14. int main(int argc, char *argv[])
    15. {
    16. QApplication app(argc, argv);
    17.  
    18. QWidget *panel = new QWidget();
    19. QVBoxLayout *layout = new QVBoxLayout(panel);
    20. panel->resize(600,600);
    21.  
    22. layout->addWidget(new QLabel("Run this a couple of times under Carbon and Cocoa, in Cocoa the proxys do not move."));
    23.  
    24. QGraphicsScene *scene = new QGraphicsScene(panel);
    25. QGraphicsView *view = new QGraphicsView(scene);
    26. layout->addWidget(view);
    27.  
    28. QLineEdit *lineEdit1 = new QLineEdit("edit 1 is going to hide now.");
    29. QGraphicsProxyWidget *item1 = new QGraphicsProxyWidget();
    30. item1->setWidget(lineEdit1);
    31. item1->setPos(10, 10);
    32. scene->addItem(item1);
    33.  
    34. QLineEdit *lineEdit2 = new QLineEdit("edit 2");
    35. QGraphicsProxyWidget *item2 = new QGraphicsProxyWidget();
    36. item2->setWidget(lineEdit2);
    37. item2->setPos(10, 40);
    38. scene->addItem(item2);
    39.  
    40. QSlider *slider = new QSlider(Qt::Horizontal);
    41. QGraphicsProxyWidget *item3 = new QGraphicsProxyWidget();
    42. item3->setWidget(slider);
    43. item3->setPos(10, 70);
    44. scene->addItem(item3);
    45.  
    46. QAxWidget *axwidget = new QAxWidget;
    47. QGraphicsProxyWidget *item4 = new QGraphicsProxyWidget();
    48. item4->setWidget(axwidget);
    49. item4->setPos(10, 110);
    50. scene->addItem(item4);
    51. axwidget->setControl("E:/ss.doc");
    52.  
    53. panel->show();
    54. return app.exec();
    55. }
    To copy to clipboard, switch view to plain text mode 
    Last edited by wysota; 4th September 2009 at 09:06. Reason: missing [code] tags

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

    Default Re: The problem when add QAxWidget into graphicsView.

    I would assume embedding QAxWidget in QGraphicsView won't work.
    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
    Sep 2009
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: The problem when add QAxWidget into graphicsView.

    Quote Originally Posted by wysota View Post
    I would assume embedding QAxWidget in QGraphicsView won't work.
    Thank you, Now I noticed that not only the QAxWidget but also the QGLWidget doesn't works. What a pitty. I really need a QAxWidget embeded in the graphicsview to show MS Office.

    Is there any idea to realize a similiar effection?

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

    Default Re: The problem when add QAxWidget into graphicsView.

    You can try having an external axwidget somewhere (possibly hidden or outside the visible screen area) and use QWidget::render() to render it to a pixmap that you can later show in the view. But I'm not sure this will work. If it did, you could have probably embedded the ax widget in the graphics view in the first place.
    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. The following user says thank you to wysota for this useful post:

    Scott Liu (7th September 2009)

  6. #5
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: The problem when add QAxWidget into graphicsView.

    Thank you for your idea, wysota.

    Now I have another question. It's like this: I put a widget in the Layout, and set a axwiget as widget's child, and show a MS office document, then a graphicsview which set as transparent widget , was ovelaped on the axwidget, then I found that the axwidget's area turn to black. Do you know the reason of it?
    and how to show the axwidget's content while a graphicsview overlaped on it?

    I really appreciate you can make me to know the way out.

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

    Default Re: The problem when add QAxWidget into graphicsView.

    I didn't understand what you asked for. Could you rephrase the question?
    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.


  8. #7
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: The problem when add QAxWidget into graphicsView.

    It looks like as attched file Img.jpg shows



    you see graphicsview first, and then if graphicsview is total transparent, you will see the axWidget, I set this effection like that:

    Qt Code:
    1. MainWindow::MainWindow(QWidget *parent)
    2. : QMainWindow(parent), ui(new Ui::MainWindow)
    3. {
    4. ui->setupUi(this);
    5. ui->gridLayout->setRowStretch(1,1);
    6. ui->gridLayout->addWidget(ui->widget,2,0,15,4);
    7. // QPushButton *btn = new QPushButton(ui->widget);
    8. ui->axWidget->setParent(ui->widget);
    9. ui->axWidget->setGeometry(0,0,ui->widget->geometry().width(),ui->widget->geometry().height());
    10. ui->axWidget->setControl("E:/ss.doc");
    11.  
    12. ui->gridLayout->setRowStretch(2,15);
    13. setCentralWidget(ui->gridLayoutWidget);
    14. scene = new QGraphicsScene;
    15. graphicsView = 0;
    16. }
    To copy to clipboard, switch view to plain text mode 

    when a button clicked:

    Qt Code:
    1. void MainWindow::on_pushButton_3_clicked()
    2. {
    3. graphicsView = new QGraphicsView(ui->widget);
    4. graphicsView->setScene(scene);
    5. graphicsView->setWindowOpacity(0);
    6. graphicsView->setStyleSheet("background: transparent");
    7. graphicsView->setParent(ui->widget);
    8. QRect rt = ui->widget->geometry();
    9. graphicsView->setGeometry(0,0,rt.width(),rt.height());
    10. graphicsView->show();
    11. QPixmap img("../black.PNG");
    12. scene->addPixmap(img);
    13. }
    To copy to clipboard, switch view to plain text mode 

    Now if I click the button, I noticed that the axwidget is all black. As I set the graphicsview as transparent ,I think the axwidget will be shown, but it isn't. I can't understand.

    So do you know the reason?
    Attached Images Attached Images
    Last edited by wysota; 7th September 2009 at 10:07. Reason: missing [code] tags

  9. #8
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,376
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Thanks
    4
    Thanked 5,019 Times in 4,795 Posts
    Wiki edits
    10

    Default Re: The problem when add QAxWidget into graphicsView.

    You should really use layouts, you know... And maybe it's not the axwidget that is black - after all you are loading a black pixmap to the scene...
    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.


  10. #9
    Join Date
    Sep 2009
    Posts
    6
    Thanks
    1
    Thanked 1 Time in 1 Post

    Default Re: The problem when add QAxWidget into graphicsView.

    In fact, even if I didn't load the black image,the axwidget also turn out to be black. I load a black image for the reason that I want to load a black image as mask, when the two layers overlap, may the axwidget's contents will show out. But it doesn't work.

Similar Threads

  1. QTimer problem ... it runs but never triggs
    By yellowmat in forum Newbie
    Replies: 4
    Last Post: 4th July 2006, 12:54
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  5. Replies: 16
    Last Post: 7th March 2006, 15:57

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
  •  
Qt is a trademark of The Qt Company.