简体   繁体   English

如何创建一个 QWidget

[英]How to create a QWidget

I'm trying to create a QWidget , but I keep getting the error:我正在尝试创建一个QWidget ,但我不断收到错误消息:

/media/root/5431214957EBF5D7/projects/c/qt/tools/plugandpaint/app/mainwindow.cpp:53: error: no matching function for call to ‘QWidget::setLayout(QScrollArea*&)’
     mainWin -> setLayout(scrollArea);
                                    ^

mainwindow.cpp主窗口.cpp

#include "mainwindow.h"

#include <QScrollArea>
#include <QApplication>

MainWindow::MainWindow() :
    scrollArea(new QScrollArea)
{
    mainWin = new QWidget();

    // Create the button, make "this" the parent
    m_button = new QPushButton("My Button", this);
    // set size and location of the button
    m_button->setGeometry(QRect(QPoint(100, 100), QSize(200, 50)));

    // Connect button signal to appropriate slot
    connect(m_button, SIGNAL (released()), this, SLOT (handleButton()));

    label = new QLabel(QApplication::translate("windowlayout", "Name:"));
    lineEdit = new QLineEdit();

    layout = new QHBoxLayout();
    layout->addWidget(label);
    layout->addWidget(lineEdit);

    scrollArea->setLayout(layout);

    mainWin -> setLayout(scrollArea);
}

mainwindow.h主窗口.h

#ifndef MAINWINDOW_H
#define MAINWINDOW_H

#include <QPushButton>
#include <QHBoxLayout>
#include <QLabel>
#include <QLineEdit>

class QActionGroup;
class QScrollArea;

class MainWindow : public QWidget
{
    Q_OBJECT

public:
    MainWindow();

private:

    QWidget *mainWin;
    QScrollArea *scrollArea;
    QStringList pluginFileNames;

    QPushButton *m_button;
    QLabel *label;
    QLineEdit *lineEdit;
    QHBoxLayout *layout;

    QVBoxLayout *vBox;
};

#endif

Here's how I try calling everything together:这是我尝试将所有内容组合在一起的方法:

#include "mainwindow.h"
#include <QtPlugin>
#include <QApplication>

#include <QDesktopWidget>

Q_IMPORT_PLUGIN(BasicToolsPlugin)

int main(int argc, char *argv[])
{
    QApplication app(argc, argv);
    MainWindow window;

    QDesktopWidget dw;

    int x=dw.width()*0.7;
    int y=dw.height()*0.7;
    window.setFixedSize(x,y);

    window.show();


    return app.exec();
}

What am I getting wrong?我怎么了? I'm a total Qt/ C++ newbie, if the problem is too obvious.如果问题太明显,我完全是 Qt/C++ 新手。

Thank you in advance.先感谢您。

First of all, I can't see anywhere a首先,我看不到任何地方

new QScrollearea()

Second, this:二、这个:

QScrollArea*&

especially the尤其是

*& *&

is most times a hint for a pointer/reference mismatch大多数时候是指针/引用不匹配的提示

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM