[Interest] First Paint Event: custom shaped widget

Konstantin Tokarev annulen at yandex.ru
Mon Feb 24 16:19:48 CET 2014



24.02.2014, 19:13, "Sensei" <senseiwa at gmail.com>:
> Dear all,
>
> in a previous post (Masked widget glitch) I asked suggestions about
> making an arrow-like widget (see picture in [1]). The old and bad code
> used a mask, but it had a glitch, as you see in the picture; however,
> the workaround was easy: doing show, hide, show. Ugly but it worked.
>
> I was suggested to move my code to a new QWidget subclass, painting the
> background, but now I'm finding it hard to create even the simplest form.
>
> What I've achieved so far is very lousy (see picture in [2]): the ugly
> hack I've used before seems better than this one.
>
> Can anyone help me understand how to draw a good-looking widget?

You should enable antialiasing - it's generally impossible to draw good-looking
triangular shapes without it.


>
> Thanks & Cheers!
>
> [1] https://dl.dropboxusercontent.com/u/15635416/mask.png
> [2] https://dl.dropboxusercontent.com/u/15635416/paint.png
>
> ToolWindow::ToolWindow(QWidget *parent, QWidget *follow) :
> QWidget(parent, Qt::FramelessWindowHint)
> {
>      setAttribute(Qt::WA_TranslucentBackground);
> }
>
> void ToolWindow::paintEvent(QPaintEvent *event)
> {
>      QPainter p(this);
>
>      const int h = 10;
>      const int w  = 12;
>
>      QPoint path[7];
>
>      path[0] = QPoint(      0,        h);
>      path[1] = QPoint(  w    ,        h);
>      path[2] = QPoint(  w * 2,        0);
>      path[3] = QPoint(  w * 3,        h);
>      path[4] = QPoint(width(),        h);
>      path[5] = QPoint(width(), height());
>      path[6] = QPoint(      0, height());
>
>      p.drawPolygon(path, 7);
> }
> _______________________________________________
> Interest mailing list
> Interest at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/interest

Regards,
Konstantin



More information about the Interest mailing list