QListView takes too long to update when given 100k items

The list widget’s layout takes too long. Set your list widget’s uniformItemSizes property to true. This avoids expensive layout operations. Another way would be to set the layoutMode property to QListView::Batched. This avoids having to expensively lay out all of the items at once. Don’t use a QListWidget if a lower overhead QListView would do. … Read more

Why does calling quit() before exec() not quit the application?

Since QCoreApplication::quit() is a no-op until the event loop has been started, you need to defer the call until it starts. Thus, queue a deferred method call to quit(). The following lines are functionally identical, either one will work: QTimer::singleShot(0, qApp, &QCoreApplication::quit); //or QTimer::singleShot(0, qApp, SLOT(quit())); // or – see https://stackoverflow.com/a/21653558/1329652 postToThread([]{ QCoreApplication::quit(); }); // … Read more

Qt 4: Move window without title bar

Try this to move the window manually: void PopupWindow::mousePressEvent(QMouseEvent *event){ mpos = event->pos(); } void PopupWindow::mouseMoveEvent(QMouseEvent *event){ if (event->buttons() & Qt::LeftButton) { QPoint diff = event->pos() – mpos; QPoint newpos = this->pos() + diff; this->move(newpos); } } And declare QPoint mpos somewhere.

Qt Layout on QMainWindow

If you want to do it with code instead of using QtCreator, you could set the layout in a QWidget and then set the QWidget as the central widget of the main window like this: #include <QtGui> #include <QWidget> #include <QHBoxLayout> #include “mainwindow.h” MainWindow::MainWindow() { // Set layout QHBoxLayout *layout = new QHBoxLayout; layout->addWidget(myWidget1); layout->addWidget(myWidget2); … Read more

Using a Qt-based DLL in a non-Qt application

Studying the Qt code it seems QCoreApplication is needed to dispatch system-wide messages such as timer events. Things like signal/slots and even QThreads do not depend on it unless they are related to those system-wide messages. Here is how I do this in a shared library (in a cross platform way using Qt itself) and … Read more

Add a define to qmake WITH a value?

DEFINES += “WINVER=0x0500” works for me. This way, -DWINVER=0x0500 is added to the command line of the compiler, which is the syntax GCC/mingw expects for command line preprocessor definitions (see here for the details).

How to make a column in QTableWidget read only?

Insert into the QTableWidget following kind of items: QTableWidgetItem *item = new QTableWidgetItem(); item->setFlags(Qt::ItemIsSelectable|Qt::ItemIsEnabled); Works fine! EDIT: QTableWidgetItem *item = new QTableWidgetItem(); item->setFlags(item->flags() ^ Qt::ItemIsEditable); This is a better solution. Thanks to @priomsrb.

QListView/QListWidget with custom items and custom item widgets

I think you need to subclass QItemDelegate. QItemDelegate can be used to provide custom display features and editor widgets for item views based on QAbstractItemView subclasses. Using a delegate for this purpose allows the display and editing mechanisms to be customized and developed independently from the model and view. This code is taken from Qt’s … Read more