Results 1 to 16 of 16

Thread: in porting Qt3 to Qt4, problem with bitBlt

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default in porting Qt3 to Qt4, problem with bitBlt

    Hi, I am trying to rewrite a Qt3 progrom in Ot4. and I am having a problem with my resizeEvent function. In Qt3 I have
    Qt Code:
    1. void edpForm::resizeEvent( QResizeEvent* event )
    2. {
    3. QPixmap save( baseBuffer );
    4. baseBuffer = QPixmap( event->size() );
    5. baseBuffer.fill( QColor( 240, 240, 255 ) );
    6. bitBlt ( &baseBuffer, 0, 0, &save );
    7. }
    To copy to clipboard, switch view to plain text mode 
    and now I get a "bitBlt" not declared in this scope. Going to the Qt3 to Qt4 documentation I find.
    To reimplement painter backends one previously needed to reimplement the virtual function QPaintDevice::cmd(). This function is taken out and should is replaced with the function QPaintDevice::paintEngine() and the abstract class QPaintEngine. QPaintEngine provides virtual functions for all drawing operations that can be performed on a painter backend.

    bitBlt() and copyBlt() are now only compatibility functions. Use QPainter::drawPixmap() instead.
    It is possible I have missed somthing in a header file someplace to cause the error message and not the change from Qt3 to Qt4. If the latter is the case some help on the proper way to handle a resize event would be appreciated.

    This is a graphic program which uses the buffer/bitBlt a great deal.

    Thanks.
    Last edited by jacek; 17th June 2006 at 20:35. Reason: changed [ code ] to [ quote ] to allow wrapping of long lines

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: in porting Qt3 to Qt4, problem with bitBlt

    I guess you can write your own bitBlt (not tested):
    Qt Code:
    1. void bitBlt( QPixmap& dst, int x, int y, const QPixmap& src )
    2. {
    3. QPainter p( &dst );
    4. p.drawPixmap( x, y, src );
    5. }
    To copy to clipboard, switch view to plain text mode 

  3. The following user says thank you to jacek for this useful post:

    impeteperry (17th June 2006)

  4. #3
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: in porting Qt3 to Qt4, problem with bitBlt

    Thanks for info, But I'm not looking for a "work around".O'Reilly in his "Programming with QT" spent a lot of time on "buffers, paintEvents, resizeEvents, mouseEvents etc." all of which had an organized structure to them.
    I use buffers for different layers in a drawing and use the "bitBlt" function to save and/or display a layer that is stored in a particular buffer.

    One of my questions was "Have they changed the procedures in Qt4 or have I screwed up. If they have changed it, I could not find documentation on it.

    I am still learning Qt programming.

    Thanks for your tip, I understasd it.

  5. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: in porting Qt3 to Qt4, problem with bitBlt

    Quote Originally Posted by impeteperry
    One of my questions was "Have they changed the procedures in Qt4 or have I screwed up. If they have changed it, I could not find documentation on it.
    I haven't read that book, so I'm not sure what is the purpose of those buffers, but now in Qt4 all widgets are double-buffered, so you don't need a buffer to avoid flicker. You might still need those buffers, if your painting routines are complex.

    As for bitBlt() --- there is no such method in Qt4, so if you want to paint one pixmap over another you have to use QPainter.

  6. The following user says thank you to jacek for this useful post:

    impeteperry (18th June 2006)

  7. #5
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: in porting Qt3 to Qt4, problem with bitBlt

    Thanks , you answared my question. Now I have to figure out what to do.

  8. #6
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: in porting Qt3 to Qt4, problem with bitBlt

    Thanks
    There is somthing simple I'm missing.

    I want to draw a line ( xs, ys, xe, ye ) on a QFrame.

    In Qt3 i had
    QPainter p( drawings ); /// set drawing pixmap
    and
    p.drawLine( xs, ys, xe, ye );
    In Qt4 with the same code I get A SIGABRT abort message.
    I have writen small program to try to work things.out.
    I used designer for the layout [IMG]/home/pete/DF-Tutorial/pgn35[/IMG] (hope you get this ).
    my header code
    Qt Code:
    1. #ifndef EDPFORM_H
    2. #define EDPFORM_H
    3.  
    4. #include <QtGui>
    5. #include <qrect.h>
    6.  
    7. #include "ui_edpform.h"
    8. class edpForm: public QMainWindow
    9. {
    10. Q_OBJECT
    11. public:
    12. edpForm();
    13. public slots:
    14. protected:
    15. void paintEvent(QPaintEvent *event);
    16. protected slots:
    17. private:
    18. Ui::edpForm ui;
    19. private slots:
    20. void slotPb1();
    21. void slotPb2();
    22. signals:
    23. void fk1clicked();
    24. void fk2clicked();
    25. };
    26. #endif
    To copy to clipboard, switch view to plain text mode 
    and the cpp file
    Qt Code:
    1. #include "edpform.h"
    2. #include <qpainter.h>
    3. #include <qpixmap.h>
    4. edpForm::edpForm()
    5. {
    6. ui.setupUi(this);
    7. connect( ui.pb3, SIGNAL( clicked() ), this, SLOT( close() ) );
    8. connect( ui.pb1, SIGNAL( clicked() ), this, SLOT( slotPb1() ) );
    9. connect( ui.pb2, SIGNAL( clicked() ), this, SLOT( slotPb2() ) );
    10. ui.input->setFocus();
    11. }
    12. void edpForm::slotPb1()
    13. {
    14. int width = ui.drawingBox->width();
    15. int height = ui.drawingBox->height();
    16. QPainter p( ui.drawingBox );
    17. p.drawLine( 0, 0, width, height );
    18. }
    19. void edpForm::slotPb2()
    20. {
    21. ui.input->clear();
    22. }
    23. void edpForm::paintEvent(QPaintEvent *event)
    24. {
    25. QPrinter printer;
    26.  
    27. ui.input->setText(" Test" ); /// when displayed show "paintEvent" has been accesed.
    28. }
    To copy to clipboard, switch view to plain text mode 
    This compiles ok, but when run I get "widget painting begins as a result of paintEvent".

    Right now I don't what I'm missing.When I start the program, it goes to the paintEvent because I get the "WoW" is the "input" box.
    I know I missing somthing simple, but I'm about brain dead over this.

    Thanks for the help.

  9. #7
    Join Date
    Jan 2006
    Posts
    667
    Thanks
    10
    Thanked 80 Times in 74 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: in porting Qt3 to Qt4, problem with bitBlt

    Why are you declaring QPrinter in the paintEvent ? You are not using it anywhere.

    The only major difference between Qt3 and Qt4 relating to this is that you cannot draw anything outside the paintEvent in Qt 4 whereas it was possible in Qt3. If you want to draw something outside the paintEvent in Qt4 then you will need to set the appropriate flags before doing this.

    From Qt docs:

    Warning: Unless a widget has the Qt::WA_PaintOutsidePaintEvent attribute set. A QPainter can only be used on a widget inside a paintEvent() or a function called by a paintEvent(). On Mac OS X, you can only paint on a widget in a paintEvent() regardless of this attribute's setting.
    Also, can we see the Qt 3 code which is working fine and the Qt 4 code which is giving the error.
    Last edited by munna; 21st June 2006 at 06:05.

  10. The following user says thank you to munna for this useful post:

    impeteperry (21st June 2006)

  11. #8
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: in porting Qt3 to Qt4, problem with bitBlt

    thanks munn, but I am still in the learning phase and I want to do things the Qt4 way which is the reason for rewriting the program.

    I understand what triggers a mouseEvent or a keypressEvent, but I don't know what triggers a paint Event.

    I look at the "circle" example, but I don't see the event that acttvates the paintEvent.

    I guess I am sort of looking for a "SIGNAL" but I know there isn't one per se. The best I can explain my understanding is, these event handlers monitor program activity and when somthing happens they like, they jump in and do their thing.

    In my program I get user input of a set of coordinates for a line. The input is in string form. I attach this string to a QStringList. Now I want to display all, some, or just one of these lines in a "ui.drawingBox" ( a QFrame In designer ).I know I can extract the numeric coordinates, scale them either in a program module or in a paint Event. But what has to happen for the paintEvent to go into action?

    What I tried to show in my last post was a simple program that had a drawing area (ui.drawingBox), QLineEdit, and 3 push buttons. "Draw", "Clear" & "Exit".
    The "user" enters " 0, 0, 50, 75".,clicks on the "draw" button and the line is displyed on the screen.

    If Trolltech would do somthing like this, a simple example for each of their functions, it would make life much simplier.

  12. #9
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: in porting Qt3 to Qt4, problem with bitBlt

    Qt will send a QPaintEvent to your widget when it needs to redraw it. For example when that widget was shown for the first time or part of it became visible after some other window has been closed. You can tell Qt that widget needs a redraw by invoking one of the QWidget::update() methods (you can also use QWidget::repaint() if you really want to).

    If you want to draw anything on a widget, you should do it in its paintEvent(). This means that either paintEvent() implementation must be able to access all information required for drawing in a short time or it will just copy the contents of a buffer (i.e. QPixmap), that was prepared earlier.

    If you have to draw a set of lines (or other objects) that can be changed by the user, you might consider using Q3Canvas.

  13. #10
    Join Date
    Jan 2006
    Location
    Riverside, Rhode Island, USA
    Posts
    245
    Thanks
    52
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11

    Default Re: in porting Qt3 to Qt4, problem with bitBlt

    What you are telling me is that a program can not directily. draw a line directly.
    If you want to draw anything on a widget, you should do it in its paintEvent(). This means that either paintEvent() implementation must be able to access all information required for drawing in a short time or it will just copy the contents of a buffer (i.e. QPixmap), that was prepared earlier.
    Llook at the "circle" example. The "window" function sends "stuff" to the "circleWidget" and somthing triggers the "paintEvent" in the circleWidged" and it does the drawing

    I can't see why or when the paintEvent kicked in

    This is what I want to do, send stuff to a module and then have the "paintEvent" in the module do its stuff.

    what event made the paintEvent kick in or what in my code dio I have to have to make my paintEvent kick in.

    I have looked at paga after page of documentation, but have not found a simple explaination that I can understand. i want to know when a paintEvent takes over so i know how to use it in the future.

    Thanks for your patients.

  14. #11
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    5,372
    Thanks
    28
    Thanked 976 Times in 912 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: in porting Qt3 to Qt4, problem with bitBlt

    Quote Originally Posted by impeteperry
    I can't see why or when the paintEvent kicked in
    In Window's contructor you have:
    Qt Code:
    1. ...
    2. connect(timer, SIGNAL(timeout()), circleWidgets[i][j], SLOT(nextAnimationFrame()));
    3. ...
    4. timer->start(100);
    To copy to clipboard, switch view to plain text mode 
    so every 100 ms CircleWidget::nextAnimationFrame() slot of each CircleWidget will be invoked.

    This slot looks like this:
    Qt Code:
    1. void CircleWidget::nextAnimationFrame()
    2. {
    3. ++frameNo;
    4. update();
    5. }
    To copy to clipboard, switch view to plain text mode 
    It just changes the frame number and invokes QWidget::update(), which notifies Qt that widget has to be redrawn (actually it just sends a QPaintEvent). A moment later QPaintEvent is picked up by the event loop, which invokes the paintEvent() method.

Similar Threads

  1. Problem in porting Main window on linux
    By jyoti kumar in forum Qt Tools
    Replies: 2
    Last Post: 2nd June 2006, 08:35
  2. problem of porting from windows to linux
    By jyoti kumar in forum Qt Programming
    Replies: 4
    Last Post: 22nd May 2006, 08:42
  3. Porting problem from Qt3 to Qt4
    By Krishnacins in forum Qt Programming
    Replies: 2
    Last Post: 19th May 2006, 14:29
  4. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  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.