PDA

View Full Version : Header and Footer



vermarajeev
6th December 2006, 03:43
Hi guys,
I have a QWidget and I'm implementing a simple painting application. I'm almost able to draw a line, circle, square etc. I'm also able to print the contents on the widget.

Now my problem is I need to provide header and footer information where the user can enter pageNo, Date, Time, Author etc( as in Microsoft Word). But I'm unable to proceed further as to how can I do that.

Please help me and if possible with some sample programs.

Thanking you in advance

wysota
6th December 2006, 08:56
I think you have to give more details - what exactly is your problem? A general answer without knowing details is to use QPainter::drawText() to draw headers and footers.

vermarajeev
6th December 2006, 09:46
I think you have to give more details - what exactly is your problem? A general answer without knowing details is to use QPainter::drawText() to draw headers and footers.

What I mean is I want to provide header and footer information in my painting application.
Simialr to Microsoft word.

Please check the below zipped file for more details. Here I have assumed the I have
a Insert->Header and Footer menuItem in MenuBar. After I click Header and Footer I should get as shown in the zipped file...

Thankx for your understanding

wysota
6th December 2006, 10:27
Ok, but what exactly is the problem? If you're using QGraphicsView then simply add another item for the header and interact with it... If you want more specific help, you have to give more details about your design.

vermarajeev
6th December 2006, 10:42
Ok, but what exactly is the problem? If you're using QGraphicsView then simply add another item for the header and interact with it... If you want more specific help, you have to give more details about your design.

Hi wysota,
thankx for your reply,

The problem is how do I initiate, what widget I should use, I'm using Qt3.3.5 on my system.

I cannot find any QGraphicsView in QtAssistant as it is defined in Qt4.x.x....

thankx

wysota
6th December 2006, 10:51
How do you implement the rest of your painting app? Do you use QCanvas?

vermarajeev
6th December 2006, 13:22
How do you implement the rest of your painting app? Do you use QCanvas?

In this class I do the drawing for my application which can extend pages. I'm maintaining matrix form for displaying the items on chemCanvas. I have also defined pageSetup for my application where user can specify different page settings eg. A4, A3, B4 etc. I'm able to print all the information present on chemCanvas to a printer using QPainter.

Now my problem is I need to provide header and footer information before printing. I know the size of printing area( i.e sizeof current page on chemCanvas). How can I do that???

Thankx,

wysota
6th December 2006, 21:44
Implement the header or footer as yet another canvas item. Alternatively you can draw directly on the canvas view using QPainter, but I think it'll be easier when you use a canvas item for that.

vermarajeev
7th December 2006, 03:07
Implement the header or footer as yet another canvas item. Alternatively you can draw directly on the canvas view using QPainter, but I think it'll be easier when you use a canvas item for that.

my class looks something like this

class chemCanvas : public QFrame
{
//some code
};

So, in this case how can I provide the header and footer area, top and bottom of the entire pages, Also what widget should I use in Qt3.3.5 to see the print preview for the added header and footer. In print preview the widget should be readonly(ie not modifyable).

When I run Microsoft word's header and footer implementation, it includes a rectangle like area for entering information, once the header and footer option in the insert menuItem is clicked. In Qt3.3.5 what widget should I use to implement the same.

I think you got what I mean
If not please let me know

thankx
Thankx

wysota
7th December 2006, 10:00
Do you place widgets inside that QFrame? I'm sorry, I just have trouble to understand how is your application implemented and you're not giving any details. Guessing again - but I take it that you draw directly on the frame, so my answer would be not to use any widgets for the header but draw it directly on the frame. I admit, that I would use the QCanvas framework instead :)

vermarajeev
8th December 2006, 03:47
Do you place widgets inside that QFrame? I'm sorry, I just have trouble to understand how is your application implemented and you're not giving any details. Guessing again - but I take it that you draw directly on the frame, so my answer would be not to use any widgets for the header but draw it directly on the frame. I admit, that I would use the QCanvas framework instead :)

Sorry,
Let me explain about my application
I have a class similar to like this


class chemCanvas : public QFrame
{
//some code to draw on QFrame using QPainter
};

//"chemEdit.cpp"
class chemEdit : public QMainWindow
{
scrollChemCanvas = new ScrollChemCanvas ( this, readonly, "scrolledCanvas" );
CHECK_PTR( scrollChemCanvas );
canvas = scrollChemCanvas->getCanvas();
setCentralWidget( scrollChemCanvas );
};

//"chemEdit.h"
//declaration for canvas and scrollChemCanvas is as follows
ChemCanvas* canvas;
ScrollChemCanvas *scrollChemCanvas;

class ScrollChemCanvas : public QScrollView
{
canvas = new ChemCanvas( viewport(), readonly );
};Here chemCanvas is the class where I do all the painting operations.
chemEdit is the QMainWindow class with all the menuItems, and other widgets
ScrollChemCanvas is the QScrollView which creates Scrollable area

Now I want to provide a Insert button in class chemEdit, which will have a popup menu Header and Footer

Insert->Header and Footer

then when I click on Header and Footer I should get a rectangular area which I think is QLineEdit (not sure), also there will be a widget with InsertAutoText, Insert PageNo, Insert Date, Insert Time etc buttons as shown in the zipped file attached.

Now first thing first what is the widget(or most suitable thing might not be a widget) that I should use for rectangular area, how can I Preview the current page on chemCanvas( just like "Print Preview").

What is the best possible way that I can use to create header and footer for my aplication?
It should be user friendly

Hope this helped you to understand!!!

Thankx

tzioboro
8th December 2006, 13:10
The best solution depends on the architecture of a document ... I have similar problem long time ago making printpreview and printing where should be a header and footer and data that have to be print may be more than one page. I used a list of "frames" where each frame can have child frames and so on. Each frame on list represent item you would like to draw on a page. Then printing algorithm was something like that:

1. Set the iterator/pointer of items to be printed on the first element of the list.
2. If we are on the beggining of the page than insert header here.
3. Knowing size of page and footer .. print each consecutive item from the list that fits in the space between header and footer.
4. Draw footer.

Than do the same on each page starting from point 2. printng rest of the items from the list.


This kind of solution will always give you psibility to print in any format A4,A3,A2.
If you still have same place between last printed item and footer but not big enough to print whole thing you may print clipping it and contiunue on next page ... it simply depends how you would like to print it.

Maybe it is not very nice solution for dynamic pages (where you have to edit thinks on page ... however I think it is still possible to do - probably there exsits better way to do it)

This is solution if you use page based edtion ... like in text processor.
If you use big plane for editing like vector drawing programs (inkscape/corel) than I do not recomend this solution.

You may use also decorator pattern. Which may be more suitable for your current priting model - I strongly suggest to get familiar with this approach at first place.