Qt QFRAME切断绘制圆圈的底部

时间:2015-03-19 20:15:54

标签: qt

我正在使用Qt 4.7.4并在QFRAME中画一个圆圈。无论我制作QFRAME的大小,我圈子的底部都被剪掉了。:

enter image description here

代码非常基本,Qframe没有特殊的属性集,默认情况下不是调色板。

我在MainWindow构造函数中实例化MyFrame:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    MyFrame* foo = new MyFrame(ui->Frame); // Frame is just a Frame widget dropped in from Qt Designer on the mainWindow
}

SubClassed QFRAME构造函数:

class MyFrame : public QFrame
{
    Q_OBJECT

public:
    explicit MyFrame(QWidget *parent):
    QFrame(parent)
{

    int w = parent->width();    // width of QFRAME
    int h = parent->height();   // height of QFRAME

    if (w == h)
    {
        Diam = w;
    }
    else if (h < w)
    {
        // Adjust diameter for smaller height
        Diam = h;
    }
    else
    {
        // Adjust diameter for smaller width
        Diam = w;
    }

    maxRadius = Diam/2 ; // Maximize circle diamater inside QFRAME

    centrePt = QPoint(w/2, h/2);
   }

MyFrame Paint事件:

    void MyFrame::paintEvent(QPaintEvent *event)
{
    QFrame::paintEvent(event);
       QPainter painter(this);
       QBrush fillStuff = QBrush(myColor, Qt::SolidPattern);
       painter.setPen(myColor);
       painter.setRenderHint(QPainter::Antialiasing, true);
       painter.setBrush(fillStuff);
       painter.drawEllipse(centrePt, maxRadius, maxRadius);

       return;
}

这是否与视口有关?

0 个答案:

没有答案