Tag Archives: Qt

Get row height and Column width of QListView

Row Height of QListView sizeHintForRow (int row); Column width of QListView sizeHintForColumn (int column)

Posted in Qt Tagged , , , ,

Set QIcon or say Icon in QListView

Create a new model class based on QSqlQueryModel and implement data() method like below:   QVariant SqlQueryModel::data ( const QModelIndex & item, int role) const { if (role == Qt::DecorationRole) { switch(item.column()) { case 0: // column 0 contains text … Continue reading

Posted in Qt Tagged , , ,

create a custom dialog box with multi line input in qt

//create a custom dialog box with multi line input void MainWindow::createMultilineInput() { //class variable dlgMultiLine = new QDialog(this);   //local variable QGridLayout *gridLayout = new QGridLayout(dlgMultiLine);   //class variable txtMultiline = new QPlainTextEdit();   txtMultiline->setObjectName(QString::fromUtf8("txtMultiline")); gridLayout->addWidget(txtMultiline, 0, 0, 1, 1); … Continue reading

Posted in Qt, Qt-Tips Tagged , ,

Qt Code Example: MessageBox

  QMessageBox::about(this, tr("About Syntax Highlighter"), tr("<p>The <b>Syntax Highlighter</b> example shows how " \ "to perform simple syntax highlighting by subclassing " \ "the QSyntaxHighlighter class and describing " \ "highlighting rules using regular expressions.</p>"));

Posted in Featured, Qt Tagged ,

Qt Code Example : Open File

void MainWindow::openFile(const QString &path) { QString fileName = path;   if (fileName.isNull()) fileName = QFileDialog::getOpenFileName(this, tr("Open File"), "", "C++ Files (*.cpp *.h)");   if (!fileName.isEmpty()) { QFile file(fileName); if (file.open(QFile::ReadOnly | QFile::Text)) editor->setPlainText(file.readAll());   } }

Posted in Featured, Qt Tagged