0

这是API 文档

我不知道如何使用它,它会有什么效果?我测试的代码如下:

#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>

class Widget : public QWidget
{
    Q_OBJECT
public:
    explicit Widget(QWidget *parent = 0);

signals:

public slots:

};

#endif // WIDGET_H

小部件.cpp

#include "Widget.h"
#include<QPushButton>

Widget::Widget(QWidget *parent) :
    QWidget(parent)
{
    QPushButton* bt = new QPushButton(this);
    this->scroll(20, 0);
}

删除时没有任何变化scroll(20, 0);,您能帮帮我吗,谢谢!

4

1 回答 1

1

QWidget::scroll() 移动已经在屏幕上绘制的小部件像素。这意味着应该在显示小部件后调用该函数。换句话说,不在构造函数中。考虑这个例子:

头文件.h

#include <QtGui>

class Widget : public QWidget
{
public:
    Widget(QWidget *parent = 0) : QWidget(parent)
    {
        new QPushButton("Custom Widget", this);
    }
};

class Window : public QDialog
{
    Q_OBJECT
public:
    Window()
    {
        QPushButton *button = new QPushButton("Button", this);
        widget = new Widget(this);
        widget->move(0, 50); // just moving this down the window
        widget->scroll(-20, 0); // does nothing! widget hasn't been drawn yet

        connect(button, SIGNAL(clicked()), this, SLOT(onPushButtonPressed()));
    }

public slots:
    void onPushButtonPressed()
    {
        widget->scroll(-20, 0);
    }

private:
    Widget *widget;
};

主文件

#include "header.h"

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);
    Window w;
    w.show();
    return a.exec();
}
于 2012-04-29T03:29:47.963 回答