簡體   English   中英

如何創建一個 QWidget

[英]How to create a QWidget

我正在嘗試創建一個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);
                                    ^

主窗口.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);
}

主窗口.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

這是我嘗試將所有內容組合在一起的方法:

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

我怎么了? 如果問題太明顯,我完全是 Qt/C++ 新手。

先感謝您。

首先,我看不到任何地方

new QScrollearea()

二、這個:

QScrollArea*&

尤其是

*&

大多數時候是指針/引用不匹配的提示

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM