Category Archives: Qt

Static cast : Pass QWidget and grab Custom class out that

/* Pass QWidget and grab MainWindow out that */   Pane::Pane(QWidget *parent) : QFrame (parent){    mainWindow = static_cast<MainWindow*>(parent);   }

Posted in Qt

QShortcut , QKeySequence and variable name as SLOT example code

QShortcut , QKeySequence and variable name as SLOT example code QShortcut *m_shortcutHiddenFunct = new QShortcut(QKeySequence(tr("Ctrl+M")),this); // m_shortcutHiddenFunct->setKey(key);   connect(m_shortcutHiddenFunct,SIGNAL(activated()) ,this, SLOT(on_shortcut_HiddenFunc_triggered()));   // m_shortcutHiddenFunct->setKey( QKeySequence(tr("Ctrl+m")));   QHash< QString, QHash<QString,QString> > mapper;   QHash<qstring , QString> bookmark; bookmark.insert("Next","Ctrl+N"); bookmark.insert("Previous","Ctrl+J");   mapper.insert("bookmark",bookmark); … Continue reading

Posted in Qt Tagged ,

QMap in reverse order using QMapIterator

//Here’s how to iterate over the elements in reverse order: QMapIterator<int , QWidget *> i(map); i.toBack(); while (i.hasPrevious()) { i.previous(); qDebug() < < i.key() << ": " << i.value(); }   //If you want to find all occurrences of a … Continue reading

Posted in Qt Tagged

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 , , ,

Different Mouse Events in Qt

bool MyQMainWindowEventFilter::eventFilter (QObject* o, QEvent* e) { // play with all mouse events if ((e->type() == QEvent::MouseButtonPress) || (e->type() == QEvent::MouseButtonRelease) || (e->type() == QEvent::MouseButtonDblClick) || (e->type() == QEvent::MouseMove)) { cout < < "mouse event" << endl; return false; } … Continue reading

Posted in Qt

Get objectname of event sender in Qt

What would be object name which sends event ? Use QObject::sender() to get the sending object. void myslot() { QObject* pObject = sender(); QString name = pObject-&gt;objectName(); }

Posted in Qt

Removing MinGW dll dependencies in QT Static linking

libgcc_s_dw2-1.dll Passing -static-libgcc will remove this dependency for all languages other than C. Note: C++ exceptions depends on this option. mingwm10.dll Remove -mthreads option from your makefile. Note: Multithreading and C++ exceptions depends on this option.

Posted in Qt, Qt-Tips Tagged , , ,

Use QColor from getColor on QLabel and QTextbox

//To use color on text and label //Simple sample :) QColor color = QColorDialog::getColor(QColor(ui->backgroundColorPickerText->text()), this); if(color.isValid()) {   QPixmap pix(21, 21); pix.fill(color);   ui->backgroundColorPickerLabel->setPixmap(pix); ui->backgroundColorPickerText->setText(color.name()); }

Posted in Qt, Qt-Tips 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 , ,