Results 1 to 11 of 11

Thread: Custom dialog

  1. #1
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Custom dialog

    how can I make custom shape dialog - know i can use image to set fixed size (don't know how it will act during resizing), but i like to create this shape inside subclass of QDialog.
    Please help.

  2. #2
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom dialog

    create your dialog with QDialog as base class, reimplement paintEvent() to create your shape. You'll have to use QPainter, read about it. It provides you with a lot of drawing capabilities with a lot of different shape. Also look at QPainterPath. Use resizeEvent() for your resizing operations. Read more about other events in QEvent.What image are you talking about? Revert back for more specific queries.

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

    simol (1st April 2009)

  4. #3
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom dialog

    Doing this i only create shape inside QDialog, right (if i'm worng i'm sorry but i'm pretty certain)? I want the dialog to be bounded by the shape and i also dont't want an active title bar to appear.

  5. #4
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom dialog

    take a look at QWidget::setMask and also take a look at this example QTDIR/examples/widgets/shapedclock.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    simol (1st April 2009)

  7. #5
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Thumbs up Re: Custom dialog

    Thanks for help. I acctualy used setMask but i didn't notice i can add QRegions (it was the key), anyway thanks again.

  8. #6
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom dialog

    I have couple more questions. How to create a QRegion to be roundedRect? And another thing: I would like this dialog to dissapear slowly (i decreas opacity of shapes i painted) on close button clicked. Painted shapes change their opacity but the region that bounds them doesn't so it doesn't look like i woudl like to. How can i do that effect (decrease region's opacity)?

  9. #7
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom dialog

    this code creates round rect widget
    Qt Code:
    1. QPixmap pixmap(300, 300);
    2. QPainter painter(&pixmap);
    3. QRectF rectangle(0.0, 0.0, 299.0, 299.0);
    4. painter.setBrush(Qt::red);
    5. painter.setPen(Qt::red);
    6. painter.drawRoundedRect(rectangle, 20.0, 15.0);
    7.  
    8. QLabel *label = new QLabel();
    9. label->setMask(QBitmap(pixmap));
    10. label->setPixmap(pixmap);
    11. label->setAttribute(Qt::WA_DeleteOnClose);
    12. label->show();
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

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

    simol (1st April 2009)

  11. #8
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom dialog

    here is an example with opacity animation (if I understand you correctly)
    Qt Code:
    1. void Test::setLabelOpacity(int opacity)
    2. {
    3. m_label->setWindowOpacity(opacity / 100.0);
    4. }
    5.  
    6. void Test::showLabel()
    7. {
    8. QPixmap pixmap(300, 300);
    9. QPainter painter(&pixmap);
    10. QRectF rectangle(0.0, 0.0, 299.0, 299.0);
    11. painter.setBrush(Qt::red);
    12. painter.setPen(Qt::red);
    13. painter.drawRoundedRect(rectangle, 20.0, 15.0);
    14.  
    15. m_label = new QLabel();
    16. m_label->setMask(QBitmap(pixmap));
    17. m_label->setPixmap(pixmap);
    18. m_label->setAttribute(Qt::WA_DeleteOnClose);
    19.  
    20.  
    21. QTimeLine *timeLine = new QTimeLine(1000, this);
    22. timeLine->setCurveShape(QTimeLine::LinearCurve);
    23. timeLine->setFrameRange(0, 100);
    24. connect(timeLine, SIGNAL(frameChanged(int)), SLOT(setLabelOpacity(int)));
    25. timeLine->start();
    26.  
    27. m_label->setWindowOpacity(0);
    28. m_label->show();
    29. }
    To copy to clipboard, switch view to plain text mode 
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  12. The following user says thank you to spirit for this useful post:

    simol (1st April 2009)

  13. #9
    Join Date
    Feb 2009
    Location
    Noida, India
    Posts
    517
    Thanks
    21
    Thanked 66 Times in 62 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Custom dialog

    u can have closeEvent() of your custom dialog like this to achieve that:

    Qt Code:
    1. void CustomDialog::closeEvent(QCloseEvent *event)
    2. {
    3. QTimeLine *timeLine = new QTimeLine(1000, this);
    4. timeLine->setCurveShape(QTimeLine::LinearCurve);//u can change this curve shape to achieve different effects, read QTimeLine
    5. timeLine->setFrameRange(0, 100);
    6. connect(timeLine, SIGNAL(frameChanged(int)),this, SLOT(setLabelOpacity(int)));
    7. connect(timeLine, SIGNAL(finished()),el, SLOT(quit()));
    8. timeLine->start();
    9. el.exec();
    10. QDialog::closeEvent(event);
    11. }
    12.  
    13. void CustomDialog::setLabelOpacity(int opacity)
    14. {
    15. setWindowOpacity(opacity / 100.0);
    16. }
    To copy to clipboard, switch view to plain text mode 

    i havent tested it but it should work

  14. #10
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Custom dialog

    yup, that will pretty cool.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  15. #11
    Join Date
    Mar 2009
    Posts
    5
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Custom dialog

    Thanks guys, appreciate your help.

Similar Threads

  1. Issue with Modelless dialog on Mac
    By Satyanarayana Chebrolu in forum Qt Programming
    Replies: 0
    Last Post: 24th February 2009, 10:10
  2. Replies: 9
    Last Post: 13th August 2008, 18:07
  3. Replies: 3
    Last Post: 18th October 2007, 08:07
  4. Resizing the dialog boxes
    By anju123 in forum Qt Programming
    Replies: 4
    Last Post: 14th September 2007, 10:41
  5. QGraphicsView: Dialog Position Doubt
    By arjunasd in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2007, 17:48

Tags for this Thread

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.