本文整理汇总了C++中QDialog::fontMetrics方法的典型用法代码示例。如果您正苦于以下问题:C++ QDialog::fontMetrics方法的具体用法?C++ QDialog::fontMetrics怎么用?C++ QDialog::fontMetrics使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QDialog
的用法示例。
在下文中一共展示了QDialog::fontMetrics方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: dia_smsg
/*! Makes a scrolled text window with the text taken from the array of
character strings in [msg] */
void dia_smsg(const char **msg)
{
char *p;
char *buf;
char *lineStart;
char *temp;
int maxline, maxrow, linesize;
long bufsize;
int i, twidth, doline;
int lastspace, curpos;
int maxWidth = (int)(0.8 * QApplication::desktop()->width());
int maxHeight = (int)(0.8 * QApplication::desktop()->height());
int height, width = 0;
QString test;
QDialog *dlg = new QDialog();
dlg->setAttribute(Qt::WA_DeleteOnClose);
for (i = 0, bufsize = 0; msg[i]; i++){
linesize = strlen(msg[i]);
bufsize += linesize;
}
buf = (char *)malloc(bufsize + i + 1);
p = buf;
for (p = buf, i = 0; msg[i]; i++) {
p += strlen (strcpy (p, msg[i]));
/* DNM: this macro call caused program built on Irix 6.5 to not run
on earlier Irix's. Casting as (int) didn't help - just do
explicit tests */
/*if (!isspace (p[-1])) spaces, tabs and newlines are spaces.. */
if (p[-1] != ' ' && p[-1] != '\t' && p[-1] != '\n')
*p++ = ' '; /* lines are concatenated, insert a space */
}
*--p = 0; /* get rid of trailing space... */
// DNM: count the actual lines and their lengths to get the right size window
maxline = 0;
maxrow = 1;
curpos = 0;
lastspace = 40;
lineStart = buf;
for (p = buf; *p; p++) {
doline = 0;
if (*p == '\t')
curpos = 8 * (curpos/ 8 + 1);
else if (*p == ' ') {
lastspace = curpos;
curpos++;
} else if (*p == '\n') {
if (curpos >= maxline)
maxline = curpos + 1;
curpos = 0;
doline = p + 1 - lineStart;
} else if (curpos > 78 ) {
if (lastspace >= maxline)
maxline = lastspace + 1;
curpos -= lastspace;
doline = lastspace;
} else
curpos++;
if (doline) {
temp = (char *)malloc(doline + 1);
if (temp) {
strncpy(temp, lineStart, doline);
temp[doline] = 0x00;
test = temp;
twidth = dlg->fontMetrics().width(test);
if (width < twidth)
width = twidth;
free(temp);
}
lineStart = p + 1;
lastspace = 40;
maxrow++;
}
}
if (!maxline & !width) {
maxline = curpos + 1;
test = "";
for (i = 0; i < maxline + 2; i++)
test += "8";
width = dlg->fontMetrics().width(test);
}
if (maxrow > 50)
maxrow = 40;
QString qmsg = buf;
// Make a vertical layout with the text edit and a close button
QVBoxLayout *vbox = new QVBoxLayout(dlg);
QTextEdit *edit = new QTextEdit(dlg);
edit->setText(qmsg);
//.........这里部分代码省略.........