利用号Qt中example 示例,如使用editor?
qt creater起始界面去搜。自动打开一个helper,code也有。

改Qt中字体??
工具-选项-文本编辑器-consolas
在编辑器最前面显示第几行?codeEditor, 同时syntax Highlighter Example也有。
找到名字之后直接网页搜就有网页版了


setViewportMargins(lineNumberAreaWidth(), 0, 0, 0);求一下当前是第几行?
blockCount是个什么??段落号查找?
lineNumber才是行号。
法1. QTextCursor tc = fileedit_window->textCursor(); //当前光标
QTextLayout *lay = tc.block().layout();
int curpos = tc.position() - tc.block().position();//当前光标在本BLOCK内的相对位置
int textline = lay->lineForTextPosition(curpos).lineNumber() + tc.block().firstLineNumber();
法2. int textline = fileedit_window->document()->lineCount(); int CodeEditor::lineNumberAreaWidth()
{
int digits = 1;
int max = qMax(1, blockCount());
while (max >= 10) {
max /= 10;
++digits;
}
int space = 3 + fontMetrics().horizontalAdvance(QLatin1Char('9')) * digits;
return space;
}
QTextCursor tc = fileedit_window->textCursor(); //当前光标
int rowNum = tc.blockNumber() + 1;//获取光标所在行的行号Notice that in a plain text edit each line will consist of one QTextBlock
实现单个词的高亮显示?
QPalette palette = textEdit->palette();
palette.setColor(QPalette::Highlight,palette.color(QPalette::Active,QPalette::Highlight));
textEdit->setPalette(palette);某一行?
QList<QTextEdit::ExtraSelection> extraSelections;//提供一种方式显示选择的文本
extraSelections = ui->plainTextEdit->extraSelections();//获取之前高亮的设置
QTextEdit::ExtraSelection selection;
selection.format.setBackground(color);
selection.format.setProperty(QTextFormat::FullWidthSelection, true);
selection.cursor = ui->plainTextEdit->textCursor();
selection.cursor.movePosition(QTextCursor::Up);//光标移动到某一行。此处移动到上一行,上一行将高亮。
extraSelections.append(selection);
ui->plainTextEdit->setExtraSelections(extraSelections);//设置高亮
ui->plainTextEdit->setExtraSelections(extraSelections);//设置高亮 QList<QTextEdit::extraSelections>This function allows temporarily marking certain regions in the document with a given color, specified as selections. This can be useful for example in a programming editor to mark a whole line of text with a given background color to indicate the existence of a breakpoint.
struct QTextEdit::ExtraSelection
The QTextEdit::ExtraSelection structure provides a way of specifying a character format for a given selection in a document.
Enum?干什么用
一年只有十二个月取值,一个星期只有七天情况,人的性别只有男女两。定义一个有限取值范围。
Enum枚举即将变量的值一一列举出来,变量只限于列举出来的值的范围内取值。
enum COLOR {red ,black, blue }; 注意:枚举中的常量之间是逗号,结构体中的变量之间是分号
枚举成员不可以重复,但是枚举值可以重复。重复枚举值的枚举成员表明它们具有共同性质,所以放在一起。
enum weeks {mon=1,tue=1,wed=1,thu=1,fri=1,sat=2,sun=2};枚举成员变量是int类型,名字则是其变量名
enum weekday {sun=1,mon,tue,wed,thu,fri,sat} day; //从1开始
int k;
printf("请输入今天星期几(1--7):");
scanf("%d",&k);
day=(enum weekday)k;
switch(day)
{
case mon: 实例一个class,它创建在堆上。实例一个struct,它创建在栈上.
类使用前必须new关键字实例化,Struct不需要
联合体union是所有变量共用一块内存,当然选占内存最大变量的内存;
每次只能发四类报文中的一种,我们可以将四类报文的结构体组织为一个union(共享一段内存,但每次有效的只是一种),然后和报文类型字段统一组织成一个报文数据结构。
typedef unsigned char BYTE;
//报文内容联合体
typedef union tagPacketContent
{
STRUCTTYPE1 pkt1;
STRUCTTYPE2 pkt2;
STRUCTTYPE3 pkt1;
STRUCTTYPE4 pkt2;
} PacketContent;
//统一的报文数据结构
typedef struct tagPacket
{
BYTE pktType;
PacketContent pktContent;
} Packet;枚举enum:枚举在C/C++/c#中,是一个被命名的整型常数的集合,枚举在日常生活中很常见。
结构体(struct)中所有变量是“共存”的——优点是“有容乃大”,全面;缺点是struct内存空间的分配是粗放的,不管用不用,全分配。
而联合体(union)中是各变量是“互斥”的——缺点就是不够“包容”;但优点是内存使用更为精细灵活,也节省了内存空间。 完全就是共用一个内存首地址,并且各种变量名都可以同时使用,操作也是共同生效。
一旦改动起来没屏蔽,不安全。
override 是什么?
描述:override保留字表示当前函数重写了基类的虚函数。
lineCount??QTextBlock Class
Returns the line count. Not all document layouts support this feature.
| int | blockCount() const |
lineNumberArea->setGeometry(QRect(cr.left(), cr.top(), lineNumberAreaWidth(), cr.height()));
没有第三个大不了字??
变成255?只剩下白色了
QColor lineColor = QColor(Qt::yellow).lighter(255);这两行确定了鼠标选择的方式。
QTextCursor tmpCursor = ui.translationInput->textCursor();
tmpCursor.movePosition(QTextCursor::Left, QTextCursor::MoveAnchor, 4);
ui.translationInput->setTextCursor(tmpCursor);
int nCurpos = tc.position() - tc.block().position();
QPoint pt(0,0);
QPoint center = pWidget->mapToGlobal(pt);
QCursor::setPos(center);See also setTextCursor().
QTextBlock block = firstVisibleBlock();
int blockNumber = 20;
开始行号20??失败???光标这。。。。
这一部分被遮住了

QPainter painter(lineNumberArea);
if (block.isVisible() && bottom >= event->rect().top()) {
QString number = QString::number(blockNumber + 1); //果然就它决定行号
painter.setPen(Qt::red);
painter.drawText(0, top, lineNumberArea->width(), fontMetrics().height(),
Qt::AlignRight, number);
}
block = block.next();自己设置光标点??
// selection.cursor = textCursor();
// selection.cursor.clearSelection();添加工具栏??两个工具栏
把mainWindow中的toolBar删掉,同时#include <qtoolBar> 才可以,记住删了之后一定点保存!
QToolBar pToolBar = addToolBar("toolBar");
QToolButton *pActionOpenBar = new QToolButton(this);
pActionOpenBar->setIcon(QIcon(":/ReplicationTool/png/open.png"));
pActionOpenBar->setToolButtonStyle(Qt::ToolButtonTextUnderIcon);
pActionOpenBar->setText(QStringLiteral("打开"));
pToolBar->addWidget(pActionOpenBar);
//添加其他按钮...
//添加分隔符
pToolBar->addSeparator();
QAction *openAction = new QAction(tr("&Open"), this);
// 添加图标
QIcon icon(":/myImages/images/fileopen.png");
openAction->setIcon(icon);
// 设置快捷键
openAction->setShortcut(QKeySequence(tr("Ctrl+O")));这个路径不行吧??? Qt中图片路径
https://www.iconfont.cn/search/index?searchType=icon&q=%E8%BF%90%E8%A1%8C
下logo网站
actionExec->setIcon(QIcon("C:/Users/xiaoleicai/source/repos/PLCController/mIcon/run.svg"));
万一换个地方执行??
actionExec->setIcon(QIcon("C:/Users/xiaoleicai/source/repos/PLCController/mIcon/run.png"));(1)绝对路径,文件的整个路径,比如
setWindowIcon(QIcon("F:/QT_PROJECT/QTtest/test/res/123.jpg"));//加载图片绝对路径 ,这种方法使用失败了。。。。得先把这个存入到qrc中去才行

actionExec->setIcon(QIcon(":/PLCController/mIcon/run.svg"));据说还可以加代码补全????
GUI qt5.0有这样的example??
三种包含class类的方式?
QPaintEvent* event是什么?
//键盘按下事件
void Widget::keyPressEvent(QKeyEvent *ev)
{
if(ev->key() == Qt::Key_F5)//F5按钮
{
}
if(ev->key() == Qt::Key_F1)//F1按钮
{
}
QEvent::MouseMove)//鼠标移动事件
QEvent::Timer)//计数器事件QResizeEvent* event 这两个还只能通过class ,来定义??
Qt的事件处理函数都是虚函数,在基类中声明,在子类中重新实现, 这些相应的事件函数在.h文件中定义在.cpp文件中重新实现函数内容
事件和信号区别??
事件处理函数的返回值是有意义的,我们要根据这个返回值来确定是否还要继续事件的处理,比如在QT中,事件处理函数如果返回true,则这个事件处理 已完成,QApplication会接着处理下一个事件,而如果返回false,那么事件分派函数会继续向上寻找下一个可以处理该事件的注册方法。信号处 理函数的返回值对信号分派器来说是无意义的
重写事件?如果鼠标点击,会造成额外影响。
object成为对象之后,就都可接受各类event??
5 #if 0
6 // 方式一:
7 #include <QTextBrowser>
8 #endif
9
10 #if 0
11 // 方式二: 比方式一可轻微提升编译速度
12 class QTextBrowser;
13 #endif
14
15 #if 1
16 // 方式三: 编译速度与方式二一样,该宏用于自编译qt源码是否启动命令空间的补充
17 QT_BEGIN_NAMESPACE
18 class QTextBrowser;
19 QT_END_NAMESPACE什么错误?虚函数未重写??

https://blog.csdn.net/silangquan/article/details/8608204
QPlainTextEdit 可以理解为 QTextEdit的低配版?都继承同一个AbstractScroll
QPlainTextEdit 可以理解为 QTextEdit的低配版。QPlainTextEdit支持纯文本显示,QTextEdit支持富文本显示。就是多一个样式。
QPlainTextEdit显示的效率比QTextEdit高,如果需要显示大量文字,尤其是需要滚动条来回滚动的时候,QPlainTextEdit要好很多。
搜:CodeEditor学习教程?
CodeEditor::CodeEditor(QWidget *parent) : QPlainTextEdit(parent)
如果继承的是QTextEdit????不可以!多处报错,比如blockCount和lineCount这些只有plainText有
- QAbstractScrollArea继承自QFrame,注意:该类不是抽象的(没有纯虚函数),只是该类的功能不够完整,所以才称为抽象的。
QPalette p1; p1.setColor(QPalette::Background,QColor(1,111,1));//绿色
pw1->setAutoFillBackground(1); //填充背景,否则部件可能会是透明的。
pw1->setPalette(p1);只要是个widget 都可以resize,即自定义一个 ——QPlainTextEdit——QAbstractScroll——Qframe——Qwidget。
QWidget::resize() and QWidget::setGeometry().
自动改变形状如何实现resizeEvent?
QResizeEvent::QResizeEvent(const QSize &size, const QSize &oldSize)
Constructs a resize event with the new and old widget sizes, size and oldSize respectively.
override并没有说一定要重写virtual?virtual = 0??故不一定。


完全没有显示??
QPlainTextEdit *testPlain = new QPlainTextEdit(); //也许他的一个特性就是,初始就是那么小,不占布局?
CodeEditor *mtxtEdit = new CodeEditor();
hlay->addWidget(testPlain);结论:QVBoxLayout是胡乱显示或者不显示的,this没有用?
至少几个Layout才有用吗?
QHBoxLayout* hlay = new QHBoxLayout();
QPushButton* btn = new QPushButton("mp", this);
QTextEdit *txtedit = new QTextEdit();
QPlainTextEdit *testPlain = new QPlainTextEdit(); //也许他的一个特性就是,初始就是那么小,不占布局?
CodeEditor *mtxtEdit = new CodeEditor(this);
QVBoxLayout* vlay = new QVBoxLayout(this);
vlay->addWidget(txtedit);
vlay->addWidget(btn);
//hlay->addWidget(testPlain);
//hlay->addWidget(txtedit);
ui.setupUi(this);this->setLayout(pLayout);
this或setLayout集体失效?????写在主程序里也不可能??


永远是空?????