我正在尝试将项目添加到QHBox,但是我一直收到错误消息:
/media/root/5431214957EBF5D7/projects/c/qt/tools/plugandpaint/app/mainwindow.cpp:36: error: no matching function for call to ‘QHBoxLayout::addItem(QPushButton*&)’
hlayout->addItem(m_button);
^
我可能做错了什么?
主窗口
#ifndef MAINWINDOW_H
#define MAINWINDOW_H
#include <QHBoxLayout>
class PaintArea;
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
MainWindow();
private slots:
void handleButton();
// Other slots
private:
PaintArea *paintArea;
QHBoxLayout *hlayout;
// Other private items
};
#endif
主窗口
MainWindow::MainWindow() :
paintArea(new PaintArea),
scrollArea(new QScrollArea)
{
// 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()));
hlayout = new QHBoxLayout;
hlayout -> addItem(m_button);
hlayout -> addItem(paintArea);
scrollArea->setWidget(hlayout);
您应该使用addWidget()代替。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句