Category Archives: Qt
capture QKeySequence from QKeyEvent
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 if (event->type() … Continue reading
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); }
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
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
Get row height and Column width of QListView
Row Height of QListView sizeHintForRow (int row); Column width of QListView sizeHintForColumn (int column)
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
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
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->objectName(); }
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.
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()); }