QT的UI界面是自定义布局,QWidget下有QLabel、QLineEdit、QPushButton、QPlainTextEdit、QTextBrower这些控件,请问怎样才能在保持布局不变的情况下,使得控件能随窗口得大小变化。并在窗口很小的情况下,增加滑动条
可以使用布局管理器来实现控件随窗口大小变化而自适应的效果。常用的布局管理器有QHBoxLayout、QVBoxLayout、QGridLayout等,它们可以把控件按照指定的方式排列,并且可以自动适应窗口大小变化。在保持布局不变的前提下,通过设置布局管理器可以实现控件自适应窗口大小的效果。
当窗口很小的时候,可以使用QScrollArea控件来实现滚动条效果。将需要滚动的控件放到QScrollArea控件中,就可以在窗口很小的情况下增加滑动条了。可以通过设置QScrollArea的大小调整策略来实现滚动条的出现,例如设置为QAbstractScrollArea::AdjustToContents,即在内容超出QScrollArea的大小时才会出现滚动条。
通常使用弹簧工具进行自适应,站内有详细教程
设置QTextEdit字体显示颜色
void setTextColor(const QColor &c)
设置html格式的内容
void setHtml(const QString &text)
设置文本
void setText(const QString &text)
设置背景颜色
void setTextBackgroundColor(const QColor &c)
设置字体
void setFontFamily(const QString &fontFamily)
设置只读
void setReadOnly(bool ro)
设置提示性文字,没有内容时显示的文字。
void setPlaceholderText(const QString &placeholderText)
往QTextEdit插入图片
QString file = "test.jpg";
QImage image(file);
QTextCursor cursor = ui->textEdit->textCursor();
QTextImageFormat imageFormat;
imageFormat.setWidth(image.width());
imageFormat.setHeight(image.height());
imageFormat.setName(file);
cursor.insertImage(imageFormat);