Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/asp.net-mvc-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在Qt中使用QWidget::scroll(intdx,intdy)?_Qt - Fatal编程技术网

如何在Qt中使用QWidget::scroll(intdx,intdy)?

如何在Qt中使用QWidget::scroll(intdx,intdy)?,qt,Qt,这是: 我不知道如何使用它,它会起什么作用?我测试的代码如下: #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 #ifndef小部件 #

这是:

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

#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
#ifndef小部件
#定义小部件
#包括
类Widget:publicqwidget
{
Q_对象
公众:
显式小部件(QWidget*parent=0);
信号:
公众时段:
};
#endif//WIDGET\u H
Widget.cpp

#包括“Widget.h”
#包括
Widget::Widget(QWidget*父项):
QWidget(父级)
{
QPushButton*bt=新的QPushButton(本);
此->滚动(20,0);
}
删除
滚动时没有任何变化(20,0),你能帮我吗,谢谢

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 <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();
}