Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.8k Posts
  • QFont::setPixelSize adds extra top padding.

    1
    0 Votes
    1 Posts
    2k Views
    No one has replied
  • Sleep problem without QThread class

    8
    0 Votes
    8 Posts
    24k Views
    G
    On unix like machins (including the Mac): @ #include <unistd.h> // sleep for 5 seconds sleep(5); // sleep for another 5 seconds (5,000,000 microseconds) usleep(5000000); @ On Windows: @ // sleep for 5 seconds (5000 milliseconds) Sleep(5000); @ Or copy the implementation of QTest::qSleep(): @ #ifdef Q_OS_WIN #include <windows.h> // for Sleep #else #include <time.h> #endif void mySleep(int ms) { if(ms <= 0) return #ifdef Q_OS_WIN Sleep(uint(ms)); #else struct timespec ts = { ms / 1000, (ms % 1000) * 1000 * 1000 }; nanosleep(&ts, NULL); #endif } @
  • Opening a Qt dialog from within a plugin (a general-type shared library)

    13
    0 Votes
    13 Posts
    5k Views
    F
    Thanks a lot Volker. I will look into that article. Best regards and thanks again!
  • [Solved] Releasing memory

    9
    0 Votes
    9 Posts
    7k Views
    G
    QSpacerItem is put into a layout (and usually not needed by user programs, use the addSpacing/addStretch methods and friends). QPixmap, QTime and QDate are usually used as stack based objects (not heap based using new), and as such don't need to be deleted manually. See my "comment":/forums/viewreply/69993/ on another thread about when to call new/delete etc.
  • Undefined reference to QMYSQLDriver

    5
    0 Votes
    5 Posts
    4k Views
    G
    [quote author="Naraha" date="1325690941"]It works now, but it seems that I have to learn the basics first. @Volker, it was already a fake username and password but never the less thanks, [/quote] Good to know it works. For fake username/password you'd better use "xxxxx" or "user"/"pass" - this way it's obvious that you didn't paste some real world credentials by accident :-)
  • Reflection over class members?

    7
    0 Votes
    7 Posts
    4k Views
    G
    [quote author="medvedm" date="1325690312"] Not sure why Volker dropped the smart-questions bomb. This doesn't seem like an unreasonable question to me. RTTI doesn't do what I am asking for, and I don't think it would have to be added in base C++. [/quote] The bomb is in the signature, everyone gets it and once I purge it, it's out of every reply :-) you can have your own signature, it's in the "edito profile"/member/profile link. [quote author="medvedm" date="1325690312"] Qt is already pulling information out about classes I write via moc, so I suppose that is why I'm asking if it is difficult to pull out some more information and make it available to users.[/quote] It would work only with QObject based classes, not for plain old classes - and for that be restricted anyways. For accessing members (you mean member methods or member attributes here?) you have the slots (for methods) and the properties (for attributes). Nothing prevents you from declaring every method as a slot, and providing a property for every attribute. I agree that the latter is cumbersome and adds some boilerplate.
  • How to add a external library on Windows

    8
    0 Votes
    8 Posts
    3k Views
    G
    You will most probably need the .hpp files and the .lib files. Without the first, your compilation fails, without the latter the linking fails. Some hints and a complete example have been given, you're supposed to adapt them to your needs.
  • How to load data in column based on previous settings.

    3
    0 Votes
    3 Posts
    2k Views
    G
    I do it this way: @ #include <QHeaderView> // to store the state: QSettings s; s.setValue("TableViewState", ui->tableView->header()->saveState()); // to restore the state: QSettings s; QByteArray tvState = s.value("TableViewState").toByteArray(); if(!tvState.isEmpty()) ui->tableView->header()->restoreState(tvState); @
  • QListWidget drag&drop

    5
    0 Votes
    5 Posts
    5k Views
    S
    I solved this, here is my code: @ void ListBox::dragMoveEvent(QDragMoveEvent *e) { if (e->mimeData()->hasFormat("application/x-item") && e->source() != this) { e->setDropAction(Qt::MoveAction); e->accept(); } else e->ignore(); } void ListBox::dropEvent(QDropEvent *event) { if (event->mimeData()->hasFormat("application/x-item")) { event->accept(); event->setDropAction(Qt::MoveAction); QListWidgetItem *item = new QListWidgetItem; QString name = event->mimeData()->data("application/x-item"); item->setText(name); /if (provider->getColumnType(name) == "text") { item->setIcon(QIcon(":/images/iString")); } else { item->setIcon(QIcon(":/images/iInteger")); }/ addItem(item); } else event->ignore(); } void ListBox::startDrag(Qt::DropActions supportedActions) { QListWidgetItem *item = currentItem(); QMimeData *mimeData = new QMimeData; QByteArray ba; ba = item->text().toLatin1().data(); mimeData->setData("application/x-item", ba); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); if (drag->exec(Qt::MoveAction) == Qt::MoveAction) delete takeItem(row(item)); } void ListBox::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasFormat("application/x-item")) event->accept(); else event->ignore(); } Qt::DropAction ListBox::supportedDropActions() { return Qt::MoveAction; } @
  • Updating the Windows style preview in QtDesigner

    4
    0 Votes
    4 Posts
    2k Views
    A
    I just said so: no. The only thing you might try, is to get yourself a recent KDE version, and find a KDE style that looks a lot like windows. I believe (not: know) that there are KDE styles that look quite a bit like more recent Windows versions.
  • Merging two columns using QSqlTableModel/QTableView

    2
    0 Votes
    2 Posts
    3k Views
    A
    Create a proxy model that does that.
  • 0 Votes
    3 Posts
    3k Views
    A
    I would use proxy models for each of your views. If you are on Qt 4.8, use [[doc:QIdentityProxyModel]] as the base for such proxies, if you are on Qt 4.7 or lower, use [[doc:QSortFilterProxyModel]] instead. In the proxy model, you simply reimplement the headerData() method to return whatever you need.
  • [Solved] QSqlDatabase memory leak.

    6
    0 Votes
    6 Posts
    9k Views
    L
    [quote author="Davita" date="1325664572"]Thank you very much Lukas, I appreciate your help. I didn't know different instance of QSqlDatabase shared same resources internally. Now I call open just once and nothing leaks anymore :)[/quote] You're welcome. Docnote to QSqlDatabase added.
  • QGraphicsScene population SLOW on Windows but not any other platform?

    2
    0 Votes
    2 Posts
    2k Views
    A
    I have no definitive answer, but a few questions that might shed some light on the issue: Have you tried turning off the BSP tree altogether using setItemIndexMethod(QGraphicsScene::NoIndex)? Is the scene invisible at the time it is populated? Is the scene attached to the view at the time it is populated? Have you tried creating the items, but NOT adding them to the scene? (Question is: Is the constructor of the items slow, or the addItem call?) Does the "40000 chips" Qt example run slowly?
  • Qpushbutton draws OpenGL problem

    5
    0 Votes
    5 Posts
    3k Views
    P
    In my code I use std::vector and create a base object class that has a virtual Render() call. I then subclass this base class for meshes and primitives. You would then in the main part of your application create a vector to hold these items. std::vector<MyDrawClass*> m_objects; as the application needs to queue objects to be rendered, you would do something like: m_objects.push_back(new Rectangle()); // Rectangle is a sub-class of MyDrawClass Then when you are ready to draw them you would do something like: @ void RenderScene() { std::vector<MyDrawClass*>::iterator it; for(it = m_objects.begin() ; it != m_objects.end; ++it) (*it)->Render(); } @ And given this example where I'm calling new (I actually use a model library that manages creation/destruction of objects as well as instancing.) when you are done though. @myApp::~myApp { std::vector<MyDrawClass*>::iterator it; for(it = m_objects.begin() ; it != m_objects.end; ++it) delete *it; m_objects.clear(); }@
  • 0 Votes
    13 Posts
    5k Views
    P
    [quote author="Andre" date="1325659958"]Could you post your whole implementation of your paintEvent()?[/quote] this is my implementation of paintevent @ void checkbox::paintEvent (QPaintEvent *e) { QCheckBox::paintEvent (e); QPainter paint(this); paint.drawPixmap (QRect(0,0,10,10), pixmap, QRect(0,0,10,10)); } @ Here i am getting both the image and the default widget as output.
  • Scroll area not working...

    7
    0 Votes
    7 Posts
    7k Views
    A
    In designer also i got it done...by adding these two line...:) @ ui->scrollAreaWidgetContents->layout()->addWidget(checkbox); ui->scrollAreaWidgetContents->layout()->addWidget(lineEdit); @ Anyway thak u so much for ur help 'pi88el'....:)
  • Building on a static version of qt

    12
    0 Votes
    12 Posts
    6k Views
    R
    <Qt Root folder>\Desktop\Qt\4.7.3\mingw\bin Here you can find, The dlls you require. When you take debug version, for example , QtCored4.dll its about 31mb. But what exactly you need is QtCore4.dll and is about 2.5 mb. same case for other libraries. Anyway, you are building statically, and you must be building the debug version.
  • C support question

    2
    0 Votes
    2 Posts
    2k Views
    J
    I'm happy to answer the question like this. ;-) answer is No. be friend with Bjarne Stroustrup
  • Draging a ListWidget item's icon to a label?

    6
    0 Votes
    6 Posts
    3k Views
    M
    [quote author="broadpeak" date="1325619302"] The drag&drop logic is the following (something like similar to this): Drag site: @ QMimeData* prepareListWidgetItem( const QString& path ) { QImage pic(path); QMimeData *mimeData = new QMimeData; mimeData->setImageData( pic ); QList<QUrl> urls; QUrl imageUrl( path ); urls.append( imageUrl ); mimeData->setUrls( urls ); mimeData->setText( imageUrl.path() ); return mimeData; } void DragLabel::mousePressEvent(QMouseEvent event) { if (event->button() == Qt::LeftButton) { QMimeData data = prepareListWidgetItem(picPath); QDrag *drag = new QDrag(this); drag->setMimeData(data); if (pixmap()) drag->setPixmap(pixmap()-> scaled(100,100, Qt::KeepAspectRatio)); drag->start(); } } @ Drop site: @ DropLabel::DropLabel(QWidget *parent) : QLabel(parent) { setAcceptDrops(true); } void DropLabel::dragEnterEvent(QDragEnterEvent event) { if (event && event->mimeData()) { const QMimeData md = event->mimeData(); if (md->hasImage() || md->hasUrls() || md->hasText()) event->acceptProposedAction(); } } void DropLabel::dropEvent(QDropEvent *event) { QPixmap pix; if(event && event->mimeData()) { const QMimeData *data = event->mimeData(); if (data->hasImage()) pix = data->imageData().value<QPixmap>(); else if(data->hasUrls()) foreach(QUrl url, data->urls()) { QFileInfo info(url.toLocalFile()); if(info.exists() && info.isFile()) pix = QPixmap(url.toLocalFile()); if (pixmap() && !pixmap()->isNull()) break; } else if(data->hasText()) { QUrl url(data->text()); QFileInfo info(url.toLocalFile()); if(info.exists() && info.isFile()) pix = QPixmap(url.toLocalFile()); } } if (!pix.isNull()) { setPixmap(pix); resize(pix.size()); } } @[/quote] I thank you for your example, but i was merely looking for the logic and the code behind ACTING upon the actual event of having dragged a ListWidget item over a label. Rest i can do myself.