本文整理汇总了C++中QTextEdit::setFixedWidth方法的典型用法代码示例。如果您正苦于以下问题:C++ QTextEdit::setFixedWidth方法的具体用法?C++ QTextEdit::setFixedWidth怎么用?C++ QTextEdit::setFixedWidth使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QTextEdit
的用法示例。
在下文中一共展示了QTextEdit::setFixedWidth方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: setLayoutItems
void CellWidget::setLayoutItems(int num)
{
QVBoxLayout* layout = (QVBoxLayout*) this->layout();
if(m_numLayoutItems < num)
{
m_checkers.resize(num);
m_editors.resize(num);
for(int i = m_numLayoutItems; i < num; i++)
{
QCheckBox* checker = new QCheckBox();
QTextEdit* editor = new QTextEdit();
editor->setReadOnly(true);
editor->setFixedHeight(20);
editor->setFixedWidth(120);
QHBoxLayout* child_layout = new QHBoxLayout();
child_layout->addWidget(checker);
child_layout->addWidget(editor);
layout->addLayout(child_layout);
m_checkers[i] = checker;
m_editors[i] = editor;
}
}
else if(m_numLayoutItems > num)
{
for(int i = num ; i < m_numLayoutItems; i++)
{
m_checkers[i]->setHidden(true);
//m_checkers[i]->setChecked(false);
m_editors[i]->setHidden(true);
}
}
m_numLayoutItems = num;
}
示例2: createThumbnail
void TextZone::createThumbnail()
{
QWidget *w = QApplication::focusWidget();
if(w){
// pixmap.fill( Qt::white );
// QPainter painter( &pixmap );
// painter.setPen( Qt::black );
//// rect.translate( 0, rect.height()+10 );
//// rect.setHeight( 160 );
// doc.setTextWidth( rect.width() );
// painter.save();
// painter.translate( rect.topLeft() );
// doc.drawContents( &painter, rect.translated( -rect.topLeft() ) );
// painter.restore();
// rect.setHeight( textDocument.size().height()-160 );
// painter.setBrush( Qt::gray );
// painter.drawRect( rect );
// pixmap.save( "text.png" );
QTextEdit tempEdit;
tempEdit.setDocument(textDocument);
tempEdit.setFixedHeight(textDocument->size().height());
tempEdit.setFixedWidth(textDocument->textWidth());
#if QT_VERSION < 0x050000
QPixmap thumbnail = QPixmap::grabWidget(&tempEdit);
#endif
#if QT_VERSION >= 0x050000
QPixmap thumbnail = tempEdit.grab();
#endif
emit textThumbnailSignal(thumbnail);
}
}
示例3: Create
void osk_dialog_frame::Create(const std::string& title, const std::u16string& message, char16_t* init_text, u32 charlimit, u32 options)
{
state = OskDialogState::Open;
static const auto& lineEditWidth = []() {return QLabel("This is the very length of the lineedit due to hidpi reasons.").sizeHint().width(); };
if (m_dialog)
{
m_dialog->close();
delete m_dialog;
}
m_dialog = new custom_dialog(false);
m_dialog->setModal(true);
// Title
m_dialog->setWindowTitle(qstr(title));
// Message
QLabel* message_label = new QLabel(QString::fromStdU16String(message));
// Text Input Counter
const QString text = QString::fromStdU16String(std::u16string(init_text));
QLabel* inputCount = new QLabel(QString("%1/%2").arg(text.length()).arg(charlimit));
// Ok Button
QPushButton* button_ok = new QPushButton("Ok", m_dialog);
// Button Layout
QHBoxLayout* buttonsLayout = new QHBoxLayout;
buttonsLayout->setAlignment(Qt::AlignCenter);
buttonsLayout->addStretch();
buttonsLayout->addWidget(button_ok);
buttonsLayout->addStretch();
// Input Layout
QHBoxLayout* inputLayout = new QHBoxLayout;
inputLayout->setAlignment(Qt::AlignHCenter);
// Text Input
if (options & CELL_OSKDIALOG_NO_RETURN)
{
QLineEdit* input = new QLineEdit(m_dialog);
input->setFixedWidth(lineEditWidth());
input->setMaxLength(charlimit);
input->setText(text);
input->setFocus();
if (options & CELL_OSKDIALOG_NO_SPACE)
{
input->setValidator(new QRegExpValidator(QRegExp("^\\S*$"), this));
}
connect(input, &QLineEdit::textChanged, [=](const QString& text)
{
inputCount->setText(QString("%1/%2").arg(text.length()).arg(charlimit));
SetOskText(text);
on_osk_input_entered();
});
connect(input, &QLineEdit::returnPressed, m_dialog, &QDialog::accept);
inputLayout->addWidget(input);
}
else
{
QTextEdit* input = new QTextEdit(m_dialog);
input->setFixedWidth(lineEditWidth());
input->setText(text);
input->setFocus();
input->moveCursor(QTextCursor::End);
m_text_old = text;
connect(input, &QTextEdit::textChanged, [=]()
{
QString text = input->toPlainText();
if (text == m_text_old)
{
return;
}
QTextCursor cursor = input->textCursor();
const int cursor_pos_new = cursor.position();
const int cursor_pos_old = cursor_pos_new + m_text_old.length() - text.length();
// Reset to old state if character limit was reached
if ((u32)m_text_old.length() >= charlimit && (u32)text.length() > charlimit)
{
input->blockSignals(true);
input->setPlainText(m_text_old);
cursor.setPosition(cursor_pos_old);
input->setTextCursor(cursor);
input->blockSignals(false);
return;
}
int cursor_pos = cursor.position();
// Clear text of spaces if necessary
if (options & CELL_OSKDIALOG_NO_SPACE)
//.........这里部分代码省略.........