

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


QMetaObject::connectSlotsByName(Widget);
这句话可以通过void Widget::on_checkBox_clicked(bool check){}这样的函数直接匹配,而不用手动添加槽
- 如果字体出现乱码,可以使用QString::fromLocalBit8(“中文”);
- 在字符串前面加上tr,tr(“中文”),tr代表翻译,QT会直接将字放到翻译文件中去
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
| #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); }
|

- Checkable 表示按钮显示选中状态和非选中状态
1
| setCentralWidget(ui->plainTextEdit);
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| 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);
|


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


