PDA

View Full Version : QStackedWidget fill Postscript image And scroll problem



patrik08
22nd April 2007, 01:10
I wand to display one ore moore QStackedWidget to paint inside a postscript image or a pdf...

the device to paint work but how i can enable scroll this QStackedWidget





class QPdf : public QMainWindow
{

//
public:
QPdf(const QString pdf_file) {

setWindowTitle ( tr( "Pdf and Postscript display.. file %1 " ).arg(pdf_file));
pages = 0;
spage = new QStackedWidget(this);

GString *ownerPW, *userPW;
doc = new PDFDoc(new GString(pdf_file),ownerPW, userPW);

if (doc->isOk()) {
qDebug() << "### doc->isOk() "<< doc->isOk();
pages = doc->getNumPages();
qDebug() << "### pages "<< pages;

for (int i=0;i<pages;i++) {
int nowrender = i + 1; /* render page pdf nr. */
qDebug() << "### page item "<< nowrender;
SplashOutputDev *onepdf = new SplashOutputDev(QSize(doc->getPageWidth(nowrender),doc->getPageHeight(nowrender)));
/////onepdf->InPaint(doc->getBitmap(nowrender));
spage->addWidget(onepdf);
}

}
setCentralWidget ( spage );
}

marcel
22nd April 2007, 01:27
Add the SplashOutputDev widgets to QScrollAreas, and add these scroll areas to the QStackedWidget, instead of adding directly the SplashOutputDev widgets.

This way you will get your scroll.

Regards

marcel
22nd April 2007, 01:31
You can use QScrollArea::sertWidget() to achieve this.

BTW: are you using XPdf?

Regards

patrik08
22nd April 2007, 01:43
You can use QScrollArea::sertWidget() to achieve this.

BTW: are you using XPdf?


Original is XPDF but i take from opie-1.2.2.tr qt3 (qtfriendly)

http://opie.handhelds.org/

Yes .. :-) is running on window on mingw compiler ... i wand to diplay fast latex result whittout acroread and paint inside point/pixel scala....

Have you a ready QT4 class to use? for my use? or a better doc from XPDF?

marcel
22nd April 2007, 01:47
No, I was just asking... I thought maybe there is another pdf library out there :)
I am working on a vector-drawing app and I plan to embed xpdf( for pdf loading ) sometimes in a near future.

Have you tried using QScrollArea?

patrik08
22nd April 2007, 02:11
No, I was just asking... I thought maybe there is another pdf library out there :)
I am working on a vector-drawing app and I plan to embed xpdf( for pdf loading ) sometimes in a near future.

Have you tried using QScrollArea?

Yes ... but not runn .... i suppose i must rewrite a wrapper to paint inside ...
but now here is europe time ... and i quit my code.... otherwise i paint the QScrollArea...



/* class SplashOutputDev : public QWidget */

SplashOutputDev::SplashOutputDev( QSize qo )
{
p = qo;
qDebug() << "### size "<< p;
scroll = new QScrollArea();
scroll->setBackgroundRole(QPalette::Dark);
scroll->ensureVisible(p.width(),p.height(),100,100);
scroll->setWidget(this);
}

marcel
22nd April 2007, 02:17
No, this is not what i meant...
Try this:


class QPdf : public QMainWindow
{

//
public:
QPdf(const QString pdf_file) {

setWindowTitle ( tr( "Pdf and Postscript display.. file %1 " ).arg(pdf_file));
pages = 0;
spage = new QStackedWidget(this);

GString *ownerPW, *userPW;
doc = new PDFDoc(new GString(pdf_file),ownerPW, userPW);

if (doc->isOk()) {
qDebug() << "### doc->isOk() "<< doc->isOk();
pages = doc->getNumPages();
qDebug() << "### pages "<< pages;

for (int i=0;i<pages;i++) {
int nowrender = i + 1; /* render page pdf nr. */
qDebug() << "### page item "<< nowrender;
SplashOutputDev *onepdf = new SplashOutputDev(QSize(doc->getPageWidth(nowrender),doc->getPageHeight(nowrender)));
QScrollArea* scrollarea = new QScrollArea( spage );
scrollarea->setWidget( onepdf );
/////onepdf->InPaint(doc->getBitmap(nowrender));
spage->addWidget(scrollarea);
}

}
setCentralWidget ( spage );
}
Here I add the SplashOutputDev widget to a scroll area, and then I add the scroll area to the QStackedWidget.
It should work like this.

Regards

marcel
22nd April 2007, 02:18
There is no need to paint to a scroll area. You can keep your code as it is, and ad scroll areas with minimal changes.

Regards

patrik08
22nd April 2007, 02:33
There is no need to paint to a scroll area. You can keep your code as it is, and ad scroll areas with minimal changes.

Regards

I look on my image displayer that display a widget and inside image on a FlowLayout that runn and scroll is visible... to append and remove image ... on qlist ...*class

but now i must display page and not tumbnail ....




void Image_Base::Load_Connector() {

comio = new Comandi(); /* top left widget command button*/

scroll = new QScrollArea(this);
scroll->setBackgroundRole(QPalette::Dark);
scroll->setMinimumWidth(500);
wrapper = new QWidget(this);
flow = new FlowLayout(wrapper);
flow ->addWidget(comio);
wrapper->setLayout(flow);
scroll->setWidget(wrapper);

}

flow ->addWidget(imagedisplay);

marcel
22nd April 2007, 02:50
Yes, and the code I've shown you should work just fine.
Isn't SplashOutputDev the widget in which you are rendering the current pdf page?
I assumed it was when I answered. Adding it to a scroll area and then adding the scroll area to the stacked widget will work.

You will not need any additional layouts or anything else...

Regards

patrik08
22nd April 2007, 09:24
Yes, and the code I've shown you should work just fine.
Isn't SplashOutputDev the widget in which you are rendering the current pdf page?
I assumed it was when I answered. Adding it to a scroll area and then adding the scroll area to the stacked widget will work.

You will not need any additional layouts or anything else...

Regards

now is run tanks...




public:
QPdf(const QString pdf_file) {

setWindowTitle ( tr( "Pdf display.. file %1 " ).arg(pdf_file));
pages = 0;
spage = new QStackedWidget(this);

GString *ownerPW, *userPW;
doc = new PDFDoc(new GString(pdf_file),ownerPW, userPW);

if (userPW) {
delete userPW;
}
if (ownerPW) {
delete ownerPW;
}
if (doc->isOk()) {
qDebug() << "### doc->isOk() "<< doc->isOk();
pages = doc->getNumPages();
qDebug() << "### pages "<< pages;

for (int i=0;i<pages;i++) {
int nowrender = i + 1; /* render page pdf nr. */
qDebug() << "### page item "<< nowrender;
QScrollArea *src = new QScrollArea(spage);
SplashOutputDev *onepdf = new SplashOutputDev(src);
/////onepdf->InPaint(doc->getBitmap(nowrender));
onepdf->SetPage(nowrender,QSize(doc->getPageWidth(nowrender),doc->getPageHeight(nowrender)));
src->setWidget(onepdf);
onepdf->setMinimumHeight(doc->getPageHeight(nowrender) + 1);
onepdf->setMinimumWidth(doc->getPageHeight(nowrender) + 50);
src->setBackgroundRole(QPalette::Dark);
spage->addWidget(src);
}

spage->setCurrentIndex(0); /* jump first */

}
setCentralWidget ( spage );
}

marcel
22nd April 2007, 09:30
Nice...


onepdf->SetPage(nowrender,QSize(doc->getPageWidth(nowrender),doc->getPageHeight(nowrender)));
src->setWidget(onepdf);
onepdf->setMinimumHeight(doc->getPageHeight(nowrender) + 1);
onepdf->setMinimumWidth(doc->getPageHeight(nowrender) + 50);
src->setBackgroundRole(QPalette::Dark);
I thought that:


onepdf->SetPage(nowrender,QSize(doc->getPageWidth(nowrender),doc->getPageHeight(nowrender)));
was already setting the size of onepdf.

EDIT:
Shouldn't you use:


onepdf->setMinimumHeight(doc->getPageWidth(nowrender) + 1);
onepdf->setMinimumWidth(doc->getPageHeight(nowrender) + 50);

You were setting page height for both minimum width and height.
Regards