Results 1 to 4 of 4

Thread: paint central widget of a QMainWindow???

  1. #1
    Join Date
    Dec 2006
    Posts
    103
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default paint central widget of a QMainWindow???

    Below are the codes. so can any1 check them n tel tht is it the right way to paint(draw line n a point) on the central widget on a menu click event?[i think its not the right way, though its working]

    form.cpp

    form.h

    form.ui

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

    Default Re: paint central widget of a QMainWindow???

    You should set an external central widget and paint on that widget and not on the main window itself.

    By the way, how is this question related to Qt Designer?

  3. #3
    Join Date
    Dec 2006
    Posts
    103
    Thanks
    31
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: paint central widget of a QMainWindow???

    Quote Originally Posted by wysota View Post
    You should set an external central widget and paint on that widget and not on the main window itself.
    so for this do i need QStackedWidget ? or simply a obj. of QWidget n set it as central widget???

    Quote Originally Posted by wysota View Post
    By the way, how is this question related to Qt Designer?
    sorry!! fm next time i wil take care..

  4. #4
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: paint central widget of a QMainWindow???

    Quote Originally Posted by Shuchi Agrawal View Post
    so for this do i need QStackedWidget ? or simply a obj. of QWidget n set it as central widget???
    The central widget can be anything inheriting from QWidget, but I think Qt Designer restricts it to be a QWidget. Just create any custom widget, reimplement the paintEvent(), add corresponding widget in the Designer and promote it.

    As I have said previously:
    Quote Originally Posted by jpn View Post
    Override QWidget::paintEvent() for the widget you want to paint on and use QPainter to draw the line. For example, if you want to paint on the central widget in a main window, you must reimplement the paintEvent() for the central widget, not for the main window.
    So, in another words.
    WRONG: "void MyMainWindow::paintEvent(QPaintEvent* event)"
    CORRECT: "void MyCentralWidget::paintEvent(QPaintEvent* event)"
    J-P Nurmi

  5. The following user says thank you to jpn for this useful post:

    Shuchi Agrawal (18th January 2007)

Similar Threads

  1. Replies: 4
    Last Post: 25th August 2014, 19:05
  2. Pin/Unpin Dock Widget
    By charlesD in forum Newbie
    Replies: 1
    Last Post: 21st June 2006, 07:57
  3. Central Widget of QMainWindow
    By sumsin in forum Qt Programming
    Replies: 3
    Last Post: 13th March 2006, 19:32
  4. [Qt 4.1.0] Split a widget on demand
    By Townk in forum Qt Programming
    Replies: 3
    Last Post: 17th February 2006, 15:16
  5. QMainWindow and its QDockWidget
    By Promethee in forum Qt Programming
    Replies: 2
    Last Post: 13th January 2006, 21:42

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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.