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.
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.
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.
simol (1st April 2009)
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.
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].
simol (1st April 2009)
Thanks for help. I acctualy used setMask but i didn't notice i can add QRegions (it was the key), anyway thanks again.
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)?
this code creates round rect widget
Qt Code:
painter.setBrush(Qt::red); painter.setPen(Qt::red); painter.drawRoundedRect(rectangle, 20.0, 15.0); label->setPixmap(pixmap); label->setAttribute(Qt::WA_DeleteOnClose); label->show();To copy to clipboard, switch view to plain text mode
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
simol (1st April 2009)
here is an example with opacity animation (if I understand you correctly)
Qt Code:
void Test::setLabelOpacity(int opacity) { m_label->setWindowOpacity(opacity / 100.0); } void Test::showLabel() { painter.setBrush(Qt::red); painter.setPen(Qt::red); painter.drawRoundedRect(rectangle, 20.0, 15.0); m_label->setPixmap(pixmap); m_label->setAttribute(Qt::WA_DeleteOnClose); timeLine->setFrameRange(0, 100); connect(timeLine, SIGNAL(frameChanged(int)), SLOT(setLabelOpacity(int))); timeLine->start(); m_label->setWindowOpacity(0); m_label->show(); }To copy to clipboard, switch view to plain text mode
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
simol (1st April 2009)
u can have closeEvent() of your custom dialog like this to achieve that:
Qt Code:
{ QEventLoop el; timeLine->setCurveShape(QTimeLine::LinearCurve);//u can change this curve shape to achieve different effects, read QTimeLine timeLine->setFrameRange(0, 100); connect(timeLine, SIGNAL(frameChanged(int)),this, SLOT(setLabelOpacity(int))); connect(timeLine, SIGNAL(finished()),el, SLOT(quit())); timeLine->start(); el.exec(); } void CustomDialog::setLabelOpacity(int opacity) { setWindowOpacity(opacity / 100.0); }To copy to clipboard, switch view to plain text mode
i havent tested it but it should work
yup, that will pretty cool.
Qt Assistant -- rocks!
please, use tags [CODE] & [/CODE].
Thanks guys, appreciate your help.
Bookmarks