


ui是Ui::Widget,这和Widget不是一个


QMetaObject::connectSlotsByName(Widget);
这句话可以通过void Widget::on_checkBox_clicked(bool check){}这样的函数直接匹配,而不用手动添加槽
#include "widget.h"
#include <QHBoxLayout>
#include <QVBoxLayout>
Widget::Widget(QWidget *parent)
:QWidget(parent)
,btn1(new QPushButton("确定",this))
,btn2(new QPushButton("取消",this))
,ckb1(new QCheckBox("粗体",this))
,ckb2(new QCheckBox("斜体",this))
,ckb3(new QCheckBox("下划线",this))
,txt(new QPlainTextEdit("ddddddd",this))
{
QHBoxLayout*Hbox1 = new QHBoxLayout;
Hbox1->addWidget(ckb1);
Hbox1->addWidget(ckb2);
Hbox1->addWidget(ckb3);
QHBoxLayout*Hbox2 = new QHBoxLayout;
Hbox2->addStretch();//加弹簧
Hbox2->addWidget(btn1);
Hbox2->addStretch();//加弹簧
Hbox2->addWidget(btn2);
QVBoxLayout* Vbox = new QVBoxLayout;
Vbox->addLayout(Hbox1);
Vbox->addWidget(txt);
Vbox->addLayout(Hbox2);
setLayout(Vbox);//将布局管理器交给窗体
}
setCentralWidget(ui->plainTextEdit);//设置主控件void MainWindow::initUI()
{
label = new QLabel("当前文件");
ui->statusBar->addWidget(label);
progressBar = new QProgressBar;
progressBar->setMinimum(5);
progressBar->setMaximum(50);
progressBar->setValue(ui->plainTextEdit->font().pointSize());
ui->statusBar->addWidget(progressBar);
spinFont = new QSpinBox;
ui->mainToolBar->addWidget(new QLabel("字体大小"));
ui->mainToolBar->addWidget(spinFont);
fontCom = new QFontComboBox;
ui->mainToolBar->addWidget(new QLabel("字体"));
ui->mainToolBar->addWidget(fontCom);
}
//设置文本格式
QTextCharFormat fmt;
ui.textEdit.mergeCurrentCharFormat(fmt);

主要要把图标放到工程文件中


