PDA

View Full Version : The problem when add QAxWidget into graphicsView.



Scott Liu
4th September 2009, 04:04
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


#include <QtGui/QApplication>
#include "mainwindow.h"
#include <QWidget>
#include <QVBoxLayout>
#include <QGraphicsScene>
#include <QGraphicsView>
#include <QLineEdit>
#include <QGraphicsProxyWidget>
#include <QSlider>
#include <QLabel>
#include <QAxWidget>


int main(int argc, char *argv[])
{
QApplication app(argc, argv);

QWidget *panel = new QWidget();
QVBoxLayout *layout = new QVBoxLayout(panel);
panel->resize(600,600);

layout->addWidget(new QLabel("Run this a couple of times under Carbon and Cocoa, in Cocoa the proxys do not move."));

QGraphicsScene *scene = new QGraphicsScene(panel);
QGraphicsView *view = new QGraphicsView(scene);
layout->addWidget(view);

QLineEdit *lineEdit1 = new QLineEdit("edit 1 is going to hide now.");
QGraphicsProxyWidget *item1 = new QGraphicsProxyWidget();
item1->setWidget(lineEdit1);
item1->setPos(10, 10);
scene->addItem(item1);

QLineEdit *lineEdit2 = new QLineEdit("edit 2");
QGraphicsProxyWidget *item2 = new QGraphicsProxyWidget();
item2->setWidget(lineEdit2);
item2->setPos(10, 40);
scene->addItem(item2);

QSlider *slider = new QSlider(Qt::Horizontal);
QGraphicsProxyWidget *item3 = new QGraphicsProxyWidget();
item3->setWidget(slider);
item3->setPos(10, 70);
scene->addItem(item3);

QAxWidget *axwidget = new QAxWidget;
QGraphicsProxyWidget *item4 = new QGraphicsProxyWidget();
item4->setWidget(axwidget);
item4->setPos(10, 110);
scene->addItem(item4);
axwidget->setControl("E:/ss.doc");

panel->show();
return app.exec();
}

wysota
4th September 2009, 09:06
I would assume embedding QAxWidget in QGraphicsView won't work.

Scott Liu
7th September 2009, 01:42
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?

wysota
7th September 2009, 04:23
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.

Scott Liu
7th September 2009, 07:23
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.

wysota
7th September 2009, 07:50
I didn't understand what you asked for. Could you rephrase the question?

Scott Liu
7th September 2009, 09:31
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:


MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent), ui(new Ui::MainWindow)
{
ui->setupUi(this);
ui->gridLayout->setRowStretch(1,1);
ui->gridLayout->addWidget(ui->widget,2,0,15,4);
// QPushButton *btn = new QPushButton(ui->widget);
ui->axWidget->setParent(ui->widget);
ui->axWidget->setGeometry(0,0,ui->widget->geometry().width(),ui->widget->geometry().height());
ui->axWidget->setControl("E:/ss.doc");

ui->gridLayout->setRowStretch(2,15);
setCentralWidget(ui->gridLayoutWidget);
scene = new QGraphicsScene;
graphicsView = 0;
}

when a button clicked:


void MainWindow::on_pushButton_3_clicked()
{
graphicsView = new QGraphicsView(ui->widget);
graphicsView->setScene(scene);
graphicsView->setWindowOpacity(0);
graphicsView->setStyleSheet("background: transparent");
graphicsView->setParent(ui->widget);
QRect rt = ui->widget->geometry();
graphicsView->setGeometry(0,0,rt.width(),rt.height());
graphicsView->show();
QPixmap img("../black.PNG");
scene->addPixmap(img);
}

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?

wysota
7th September 2009, 10:08
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...

Scott Liu
9th September 2009, 06:39
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.