保护功能只能在类中被使用,所以它产生的错误。我已经通过设计CustomPlainText
课程并将其推广到原来的QPlainTextEdit
来解决它,其中我使用了setViewportMargins (10,10,10,10);
。如果你想从课堂外访问该功能,我已经创建了功能CustomSetViewportMargins({args})
。
点击右键并选择:推广到...
编写类和头的名称,并添加它。
,并按推广。
customplaintext.cpp
#ifndef CUSTOMPLAINTEXT_H
#define CUSTOMPLAINTEXT_H
#include <QPlainTextEdit>
class CustomPlainText:public QPlainTextEdit
{
Q_OBJECT
public:
CustomPlainText(QWidget * parent = 0);
void CustomSetViewportMargins(int left, int top, int right, int bottom);
void CustomSetViewportMargins(const QMargins & margins);
};
#endif // CUSTOMPLAINTEXT_H
customplaintext.h
#include "customplaintext.h"
CustomPlainText::CustomPlainText(QWidget *parent): QPlainTextEdit(parent)
{
setViewportMargins(10,10,10,10);
}
void CustomPlainText::CustomSetViewportMargins(int left, int top, int right, int bottom)
{
setViewportMargins(left, top, right, bottom);
}
void CustomPlainText::CustomSetViewportMargins(const QMargins & margins)
{
setViewportMargins(margins);
}
前:
后:
完整代码:https://github.com/eyllanesc/stackoverflow/tree/master/CustomPlainTextProject
你在哪里调用这个函数?请给更多的信息 – Youssef
从manwindow.cpp文件。我只需要从mainwindow.cpp中改变textEdit的边距。 – charles