Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.4k Posts
  • QTableWidget Column Hold More Than One Item

    Solved
    3
    0 Votes
    3 Posts
    150 Views
    P
    Oh, right. Thanks, I just tried it and it works exactly. Just put it in an if-statement to check if it's at the end of the array so I can see if I need a comma or not.
  • Add widget right aligned to a QTableWidget cell

    Solved
    46
    0 Votes
    46 Posts
    8k Views
    H
    @VRonin said in Add widget right aligned to a QTableWidget cell: I assume you mean setItemDelegateForRow and setItemDelegateForColumn. yes, I copied and pasted n forgot to modify before submitting. Thanks
  • How to pass argc and argv to MainWindow object

    Solved
    8
    0 Votes
    8 Posts
    3k Views
    Christian EhrlicherC
    How about looking at the QString documentation? QString::toLatin1(), QString::toUtf8() for example. And why do you need a char** at all? What are you trying to do?
  • KDGantt Chart Layout Help

    Solved
    3
    0 Votes
    3 Posts
    404 Views
    P
    I found it. I had to get access to the left pane and then set the width. Thank you for the help! view->leftView()->setMaximumWidth(100);
  • QTableWidgetItem will use a spinbox for editor automatically if setData is called

    Solved
    7
    0 Votes
    7 Posts
    1k Views
    jronaldJ
    @VRonin said in QTableWidgetItem will use a spinbox for editor automatically if setData is called: class IntLineEditCreator : public QItemEditorCreatorBase { public: IntLineEditCreator() = default; QWidget* createWidget(QWidget *parent) const override{ return new QLineEdit(parent); } QByteArray valuePropertyName() override{ return QByteArrayLiteral("text"); } }; then you can use it with something like: IntLineEditCreator* creator = new IntLineEditCreator; QItemEditorFactory *factory = new QItemEditorFactory; factory->registerEditor(QMetaType::Int, creator); factory->registerEditor(QMetaType::UInt, creator); tableWidget->delegate()->setItemEditorFactory(factory); connect(tableWidget,&QObject::destroyed,creator,factory{delete creator; delete factory;}); Awesome, thanks
  • How to get the correct QSqlError?

    Unsolved
    12
    0 Votes
    12 Posts
    2k Views
    D
    These errors also vary depending on which object I'm using (QSqlQueryModel or QSqlQuery ) and with a valid database. Here's the error I got with QSqlQueryModel: [image: eedc5564-2783-45a6-b2a1-4151d6fbc9f1.gif] To code is: else{ QSqlQueryModel sqlQuery; bool gotError = false; db.transaction(); for (int i = 0; i < statements.size(); i++) { auto trimmed = statements[i].trimmed(); if(trimmed.startsWith("--")) continue; sqlQuery.setQuery(trimmed); if(sqlQuery.query().isSelect()){ emit widget->logMessage("e,SELECT isn't allowed while executing multiple statements"); gotError = true; break; } else if(sqlQuery.query().lastError().type() != QSqlError::NoError){ emit widget->logMessage("e," + sqlQuery.query().lastError().text()); gotError = true; break; } } ... } so it's correct, NewTable exists. If I replace those code with these: else{ bool gotError = false; db.transaction(); for (int i = 0; i < statements.size(); i++) { auto trimmed = statements[i].trimmed(); if(trimmed.startsWith("--")) continue; sqlQuery.clear(); sqlQuery.prepare(trimmed); sqlQuery.exec(); if(sqlQuery.isSelect()){ emit widget->logMessage("e,SELECT isn't allowed while executing multiple statements"); gotError = true; break; } else if(sqlQuery.lastError().type() != QSqlError::NoError){ emit widget->logMessage("e," + sqlQuery.lastError().text()); gotError = true; break; } } ... } where sqlQuery is a global QSqlQuery, I get this error: [image: bda81e3f-6bf0-4b63-a7ee-e5815fd3b278.gif] that's a misleading error I got! Am I doing something wrong or it's an issue with SQLite? EDIT Looks like QSqlQuery doesn't need to be executed to get error. I've to check error immediately after sqlQuery.prepare(trimmed); and if there's no error then I should call sqlQuery.exec(). In a nutshell, Qt executes the query, and figures out the error, before I call exec.
  • trouble with height-for-width

    Solved
    5
    0 Votes
    5 Posts
    376 Views
    D
    Hi, just to close this: I compiled a Qt with debug info and debugged the layout process. Then I thought, I should extend QLayout::totalSizeHint() - but that function is not virtual. So patching Qt would become expensive :( So I thought, may be QScrollArea has a property for preferred extend direction - which is not the case. But on that research I discovered QScrollArea::setWidgetResizable() ... Oh happy day! That did the trick :) I have nothing to extend or patch, just use this property. What a revelation :D Finally my code looks something like this: Window::Window() : client(new QWidget(this)) { FlowLayout* fl = new FlowLayout; QScrollArea* sa = new QScrollArea; setLayout(new QVBoxLayout); layout()->setMargin(0); client->setLayout(fl); fl->setMargin(0); fl->addWidget(...); fl->addWidget(...); ... sa->setWidget(client); sa->setWidgetResizable(true); layout()->addWidget(sa); } ... and the result looks like: [image: 90fd78c8-892a-4271-8e1d-77643207d376.png] Yeah!
  • QFontDialog doesn't return (sometimes) QFont with correct styleName

    Unsolved
    1
    0 Votes
    1 Posts
    150 Views
    No one has replied
  • How my software can catch/avoid "No carrier" response from QNetwork?

    Solved
    3
    1 Votes
    3 Posts
    1k Views
    V
    Qt 5.15.2 In my case it was network config manager that generated those "No carrier" messages. There's a plugin called qconnmanengine (qtbase/src/plugins/bearer/connman) which in case of wifi bearer periodically scans for wifi. You can simply reproduce this issue just by disable wifi technology (connmanctl disable wifi). void QConnmanTechnologyInterface::scanReply(QDBusPendingCallWatcher *call) { QDBusPendingReply<> props_reply = *call; if (props_reply.isError()) { qDebug() << props_reply.error().message(); } Q_EMIT scanFinished(props_reply.isError()); call->deleteLater(); }
  • How to transffer QImage or QPixmap from one window to another using signals and slots

    Solved
    29
    0 Votes
    29 Posts
    3k Views
    JonBJ
    @swansorter Additionally to @jsulm, you originally had it with your connect(test_label,&my_qlabel::sendImage,this,&MainWindow::onGetImage); You then changed over to SIGNAL/SLOT, for no discernible reason, which may be a clue as to why it went wrong....
  • QT Terminate Browser Process

    Unsolved
    8
    0 Votes
    8 Posts
    1k Views
    JonBJ
    @Dusk-Le You are already spawning the Chrome.exe as a child of your Qt app. If QProcess::kill() does not work you have a problem. Quite possibly because like I suggested the original QProcess you spawn is not kept as the process for the resulting opened window, due to Chrome internals. Start by Googling for, say, kill one chrome process or kill one chrome window, to see how difficult/easy this is. Then if you don't kind a better way, start with the following: Keep your process.start(). You might want to add qDebug() << process.processId(); after it, for use below. Comment out msleep/close/kill(). Let the Chrome run up its window/page/tab. Go into Windows Task Manager. Look through all the (scary number of!) running Chrome processes. (Hint: You may want to View > Select Columns... > find and check the Command Line column.) By experimenting with End Process them, find which one (or ones?) you need to terminate to achieve the right one for your window. Then use Windows EnumProcesses etc. to determine how you can find that desired process(es), and Windows calls to kill it.
  • This topic is deleted!

    Solved
    11
    0 Votes
    11 Posts
    21 Views
  • Transparent QMainWindow for Raspberry Pi

    Solved
    2
    0 Votes
    2 Posts
    706 Views
    R
    It took a while to figure out, but it's finally working. For anyone else with this issue: Use the raspi-config command, go to advanced settings and enable Compositor. Run the xcompmgr command and then try the program again. Transparency now works!
  • Qt5 and Qt6 Bluetooth crashes on segmentation fault.

    Solved
    5
    0 Votes
    5 Posts
    538 Views
    Z
    The similar problem: https://forum.qt.io/topic/119766/unknown-exception-is-not-beeing-caught-in-trycatch-block-bluetooth-low-energy-servicedetailsdiscovery
  • Qt Multimedia not working

    Unsolved
    14
    0 Votes
    14 Posts
    1k Views
    jsulmJ
    @Padawan said in Qt Multimedia not working: I should also deselect it from qt 6.1.0 ? If you don't need it then yes
  • For QTableWidget, what's the difference of cellChanged and itemChanged?

    Solved
    4
    0 Votes
    4 Posts
    2k Views
    SGaistS
    Hi, cellChanged is for all QAbstractItemView classes, itemChanged is specific to the convenience views (QListWidget, QTableWidget, QTreeWidget) where you use the corresponding item classes to interact with the model.
  • Is it possible to fill color inside a bounding rectangle?

    Unsolved
    2
    0 Votes
    2 Posts
    177 Views
    jsulmJ
    @Swati777999 There are various https://doc.qt.io/qt-5/qpainter.html#fillRect methods - aren't those what you need?
  • Why mouserelease event not working on qlable

    Solved
    9
    0 Votes
    9 Posts
    1k Views
    S
    @Pl45m4 Ha yes i was using ui->label->installEventFilter(this); in the main window .Now disabled it and mouse release event is working
  • How do you save and restore the state of QTreeView?

    Solved
    3
    0 Votes
    3 Posts
    2k Views
    D
    @JonB, look at that: void ObjectsView::makeTree() { QStandardItemModel *model; QMap<QString, QStringList*> expanded; if(tree->model()){ for (int row = 0; row < tree->model()->rowCount(); row++) { auto index = tree->model()->index(row, 0); if(!tree->isExpanded(index)) continue; auto node = tree->model()->data(index).toString(); auto trimmed = node.left(node.indexOf(' ')); auto list = new QStringList; expanded.insert(trimmed, list); for (int child = 0; child < tree->model()->rowCount(index); child++) { auto childIndex = tree->model()->index(child, 0, index); if(!tree->isExpanded(childIndex)) continue; node = tree->model()->data(childIndex).toString(); trimmed = node.left(node.indexOf(' ')); list->append(trimmed); } } tree->model()->removeRows(0, tree->model()->rowCount()); model = qobject_cast<QStandardItemModel*>(tree->model()); } .... // rest of the code .... for (int row = 0; row < tree->model()->rowCount(); row++) { auto index = tree->model()->index(row, 0); auto node = tree->model()->data(index).toString(); auto trimmed = node.left(node.indexOf(' ')); if(!expanded.keys().contains(trimmed)) continue; tree->setExpanded(index, true); if(expanded.value(trimmed)->size()){ auto list = expanded.value(trimmed); for (int child = 0; child < tree->model()->rowCount(index); child++) { auto childIndex = tree->model()->index(child, 0, index); node = tree->model()->data(childIndex).toString(); trimmed = node.left(node.indexOf(' ')); if(list->contains(trimmed)) tree->setExpanded(childIndex, true); } } } qDeleteAll(expanded.values()); } and somehow it works: [image: f615ceb4-cfe8-48d3-ab1f-89056b3d1daf.gif] Any suggestion for improvement?
  • Can't adjust font size of QGraphicsTextItem in QGraphicsRectItem

    Solved
    10
    0 Votes
    10 Posts
    1k Views
    JoeCFDJ
    @leinad override paint and set font to painter. It will work.