Results 1 to 6 of 6

Thread: Problem drowing in tabWidget...

  1. #1
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4

    Default Problem drowing in tabWidget...

    Problem drowing in tabWidget...
    I'm having a problem with a simple QWidget program that draws an ellipse inside a child tabWidget (in sоme of tabs).

    I have Main ui form and a tabWidget in it.

    Here is part of the code:

    Qt Code:
    1. void MainWindow::paintEvent(QPaintEvent *event)
    2. {
    3. QPainter painter(ui->tab_2);
    4. painter.setRenderHint(QPainter::Antialiasing, true);
    5. painter.setPen(QPen(Qt::black, 12, Qt::ashDotLine, Qt::RoundCap));
    6. painter.setBrush(QBrush(Qt::green, Qt::olidPattern));
    7. painter.drawEllipse(80, 80, 400, 240);
    8. }
    To copy to clipboard, switch view to plain text mode 

    Line 3 QPainter painter(ui->tab_2); doesn't do anything. The program draws the ellipse only if I replace line 3 with QPainter painter(this); but that draws on the parent QWidget (Main form) and not on the child QWidget (tabWidget) as desired.

    Any Suggestion?

    Thanks!
    Last edited by wysota; 9th December 2009 at 08:25. Reason: missing [code] tags

  2. #2
    Join Date
    Sep 2009
    Location
    Tashkent, Uzbekistan
    Posts
    107
    Thanks
    1
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Problem drowing in tabWidget...

    Hi,
    can you enclose the code with \[CODE\]\[\/CODE\] next time and where is the ui declaration?

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

    Default Re: Problem drowing in tabWidget...

    Quote Originally Posted by dspfen View Post
    Line 3 QPainter painter(ui->tab_2); doesn't do anything.
    Yes it does. It issues a warning on your console stating that you can only paint on a widget from within its paint event. And currently you are in paint event of a different widget.

    Any Suggestion?
    Install an event filter on the child widget and intercept its paint event there. You can draw from within the intercepted event.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  4. #4
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4

    Question Re: Problem drowing in tabWidget...

    Marci for your replay, but I don't know how to install an event filter on the child widget and intercept its paint event in my project.
    In the link below is my project.
    Attached Files Attached Files

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

    Default Re: Problem drowing in tabWidget...

    Open Qt Assistant, go into index tab and type in "event filter".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


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

    dspfen (10th December 2009)

  7. #6
    Join Date
    Dec 2009
    Posts
    3
    Thanks
    1
    Qt products
    Qt4

    Thumbs up Re: Problem drowing in tabWidget...

    Super!
    Еverything is working now as I want due to the help of wysota.
    Thank you very much!

Similar Threads

  1. deployment problem: msvc++ 2008 Express, Qt 4.4.3
    By vonCZ in forum Qt Programming
    Replies: 7
    Last Post: 10th November 2008, 14:38
  2. Grid Layout Problem
    By Seema Rao in forum Qt Programming
    Replies: 2
    Last Post: 4th May 2006, 12:45
  3. Problem with bitBlt
    By yellowmat in forum Newbie
    Replies: 1
    Last Post: 5th April 2006, 14:08
  4. fftw problem
    By lordy in forum General Programming
    Replies: 1
    Last Post: 16th March 2006, 21:36
  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
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.