Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
84.0k Topics 460.2k Posts
Qt 6.11 is out! See what's new in the release blog
  • Reporting inappropriate content on the forums

    Pinned Locked spam
    29
    4 Votes
    29 Posts
    54k Views
    A
    Thank you for the report. I have banned the user, which got rid of the spam posting. Not a loss, as this user did not post any other content on the site. Just deleting this one posting was not possible. Thanks for reporting this.
  • 0 Votes
    8 Posts
    3k Views
    K
    Coming back (after 2 years ! ) to close this out, since I finally have a solution that's held up in production. Short answer: you can't get a real inline dropdown in Designer's Property Editor from pure Python. That specific bit needs a compiled C++ plugin. But there's a Python path that works well in practice — I'll explain both. What doesn't work (so you can skip the dead-ends I hit): I tried a QDesignerPropertySheetExtension to swap the property's editor. On PySide6 6.11: You can't delegate to Designer's built-in sheet — extensionManager().extension(...) hands it back as a bare QObject and shiboken can't recover the real interface, so the methods just aren't there. Replacing the sheet wholesale with a Python-built one segfaults Designer during form load — even when every property returns a plain string. Its core assumes the internal C++ sheet. Also worth knowing: declaring the property as a Q_ENUM/@QEnum does give you a dropdown, but only for static, compile-time enums baked into the widget. It's no help if your options are computed at runtime (mine come from a project file), which was the whole point. What actually works — a task-menu extension: Right-click the widget → your action pops a combo box → you write the choice back through the form cursor. It's undo-aware, dirties the form, and saves to the .ui like any normal edit. from PySide6.QtDesigner import (QExtensionFactory, QPyDesignerTaskMenuExtension, QDesignerFormWindowInterface) from PySide6.QtGui import QAction from PySide6.QtWidgets import QInputDialog TASKMENU_IID = "org.qt-project.Qt.Designer.TaskMenu" class ThemeTaskMenu(QPyDesignerTaskMenuExtension): def __init__(self, widget, parent=None): super().__init__(parent) self._widget = widget self._action = QAction("Set theme…", self) self._action.triggered.connect(self._choose) def taskActions(self): return [self._action] def _choose(self): names = ["Light", "Dark", "Solarized"] # build this list at runtime current = self._widget.property("appTheme") or "" i = names.index(current) if current in names else 0 name, ok = QInputDialog.getItem(self._widget.window(), "Theme", "Theme:", names, i, False) if not ok or not name: return fw = QDesignerFormWindowInterface.findFormWindow(self._widget) # cursor path = undoable + saved to the .ui; a raw setProperty won't stick (fw.cursor().setWidgetProperty(self._widget, "appTheme", name) if fw else self._widget.setProperty("appTheme", name)) class ThemeTaskMenuFactory(QExtensionFactory): def createExtension(self, obj, iid, parent): if iid != TASKMENU_IID or not isinstance(obj, MyCustomWidget): return None return ThemeTaskMenu(obj, parent) Register it in your plugin's initialize(core): core.extensionManager().registerExtensions( ThemeTaskMenuFactory(core.extensionManager()), TASKMENU_IID) Two things that bit me: Apply via fw.cursor().setWidgetProperty(...), not just widget.setProperty(...) — otherwise the change never makes it into the saved .ui. Keep the underlying property a plain, validated @Property(str). The menu is only an input aid; the stored value stays portable and works fine on machines without your plugin. If you have both PyQt5 and PySide6 installed, launch designer with QT_API=pyside6 or qtpy may pick PyQt5 and your plugin import will fail. So: static enum → Q_ENUM. Runtime options → task-menu extension. True inline dropdown → C++ only. I use a slightly fancier version of this (a little dock with a combo per property) in my widgets library if anyone wants a fuller reference: https://github.com/SpinnCompany/QT-PyQt-PySide-Custom-Widgets Marking this solved — hope it saves someone the segfault hunt.
  • Problem getting QGraphicsItem::mousePressEvent to trigger

    Unsolved
    1
    0 Votes
    1 Posts
    39 Views
    No one has replied
  • QDrag pixmap changes between Qt 6.4 and 6.10?

    Unsolved
    2
    0 Votes
    2 Posts
    72 Views
    SGaistS
    Hi and welcome to devnet, Are you in both cases using the distribution provided Qt ? Can you check with a more recent version to see if it's still acting up ? Did you check, when launching from the terminal, if there's any system generated message about the pixmap ?
  • Launch telnet from Qt GUI application

    Unsolved
    16
    0 Votes
    16 Posts
    310 Views
    JonBJ
    @Christian-Ehrlicher said in Launch telnet from Qt GUI application: and don't use QProcess::startDetached() if you want to interact with your application and That's the whole point of this function - fire and forget https://doc.qt.io/qt-6/qprocess.html#startDetached Hi Christian. I am sorry but I do not agree with your statements. Under Linux at least startDetached() causes the child process not to get killed when the parent process exits, but it is not true to say that means you do not use if you need interaction. Testing under Linux at least, where telnet does not open its own window (maybe it does under Windows, I don't know) while, say, gedit does, I see the following behaviour: start("telnet"): runs telnet (in the background), no window, exiting Qt app kills the telnet. startDetached("telnet"): same as start(), but exiting Qt app does not kill the telnet. start("gedit"): runs gedit, that creates its own window and interacts fine, exiting Qt app kills the gedit. startDetached("gedit"): same as start(), but exiting Qt app does not kill the gedit. If I want a Linux spawned telnet to be visible and have a window I have to use something like e.g. xterm -e telnet as the command. And again that behaves as above: dies on parent exit with start(), continues to run afterwards with startDetached(), but same interaction in both cases. Maybe it's different under Windows and/or with telnet there, but saying that "and don't use QProcess::startDetached() if you want to interact with your application" is not the story under Linux at least. Which is why I expressed my surprise when you wrote that, as not my experience in Linux.
  • Beware of nested event loops

    Unsolved
    5
    3 Votes
    5 Posts
    125 Views
    JonBJ
    @SimonSchroeder said in Beware of nested event loops: @JonB Just one wild guess what's different: In my case the event loop is also already running. You are doing a.exec() only after dlg1.exec(). So, this is one less nesting level. FWIW, and for completeness, I changed above code from running dlg1.exec(); immediately before a.exec() to QTimer::singleShot(3000, [&dlg1]() { dlg1.exec(); } ); Behaviour is same: dialogs hide and show as expected, no missing "re-show". It is true that I am Linux and Qt6 while you are Windows and Qt5. I don't know if one of those is the difference.
  • How to change QTabBar close button size

    Unsolved
    5
    0 Votes
    5 Posts
    2k Views
    X
    i tried, only QProxyStyle class CloseButtonRightStyle : public QProxyStyle { public: using QProxyStyle::QProxyStyle; int styleHint(StyleHint hint, const QStyleOption *option = nullptr, const QWidget *widget = nullptr, QStyleHintReturn *returnData = nullptr) const override { if (hint == QStyle::SH_TabBar_CloseButtonPosition) return QTabBar::RightSide; return QProxyStyle::styleHint(hint, option, widget, returnData); } int pixelMetric(PixelMetric metric, const QStyleOption *option = nullptr, const QWidget *widget = nullptr) const override { if (metric == QStyle::PM_TabCloseIndicatorWidth || metric == QStyle::PM_TabCloseIndicatorHeight) return 24; // iconSize return QProxyStyle::pixelMetric(metric, option, widget); } }; use ui->document->tabBar()->setStyle(new CloseButtonRightStyle(ui->document->style()));
  • Get margins of QPushButton

    Solved qtwidgets qss
    15
    1 Votes
    15 Posts
    15k Views
    SGaistS
    @Sordayne said in Get margins of QPushButton: This bug seems to have not been fixed in Qt 6.10. Have you found a solution? Hi and welcome to devnet, In that case, you should check the bug report system and if there's nothing, please open a new report providing a minimal compilable example that shows the issue.
  • DragHandler::onDragChanged not reporting continously

    Solved
    6
    0 Votes
    6 Posts
    393 Views
    JKSHJ
    You're welcome! @kaixoo said in DragHandler::onDragChanged not reporting continously: I'm also looking to register when the user clicks the middle mouse button + drags their mouse. DragHandler only registers events from the left click Set your acceptedButtons: https://doc.qt.io/qt-6/qml-qtquick-draghandler.html#acceptedButtons-prop I see now that handlerPoint has no signals though, how am I supposed to signal when the position has changed? handlerPoint is a value type, like date or string. The string doesn't emit a signal either when a character gets modified. Rather, the whole value gets updated. Putting these together: DragHandler { acceptedButtons: Qt.MiddleButton onCentroidChanged: { if (active) console.log("Centroid moved to", centroid.position) } }
  • Relevance of invokeMethod() in multithreaded programs

    Solved
    8
    0 Votes
    8 Posts
    626 Views
    S
    Basically, the other answers already contain all of my thoughts. But, since I've been mentioned I'll still chime in. In a single-threaded context I can just call functions and that's fine. In a multi-threaded context when I want to call functions of an object that lives in a different thread (especially if you want to call GUI functions in Qt) invokeMethod() is the only easy way I know of. Sure, you can properly set up a signal. I personally don't see the point in having a signal (which I then need to connect) if it is called from just a single place in the code. First, I have to come up with an appropriate name for the signal, and second, I'll have a long list of signals in the class declaration that are of no interest to any outsider. The use case of of using this to call functions belonging to a GUI thread is so pervasive that I have a header-only library that (among other things) has a function guiThread(...) (https://github.com/SimonSchroeder/QtThreadHelper) to easily place calls into the GUI thread from other threads. From the recent discussion in this forum I have also learned that invokeMethod() takes a connection type as argument. I guess, then my function guiThreadMaybe() is not necessary, as the default is the AutoConnection which will do already a direct call if it is from the same thread (the 'maybe' part explicitly checks for that). Outside of multi-threading I only see a single use case for invokeMethod(): If I don't want to immediately execute that function, but put it in the event queue to be executed at a later point. I guess this is a valid use case, but not one I encounter often. In many cases, the suggested solution is a single shot timer with a timeout of 0ms. In addition to putting this call into the event loop, it will also only execute once the event loop is otherwise idle. @JonB said in Relevance of invokeMethod() in multithreaded programs: I didn't see why there is a particular mention here of separate threads. It wasn't mentioned in the original post, but later: @Christian-Ehrlicher said in Show a QMessage box from the context of a function defined outside mainwindow.cpp: One problem with a simple callback will arise when you run the solver in a different thread. "invokeMethod() is also my general solution if I'm multithreaded" needs to be read in the context of the original discussion: It was specifically about calling GUI functions. If we combine that with multithreading, invokeMethod() is the (hard-to-find) obvious solution.
  • Show a QMessage box from the context of a function defined outside mainwindow.cpp

    Unsolved
    15
    0 Votes
    15 Posts
    1k Views
    JKSHJ
    @lukester88 said in Show a QMessage box from the context of a function defined outside mainwindow.cpp: A major theme I have in my code is keeping UI code and solver code completely separate, and I would like to continue that trend with this specific task. My question is - how can I make these functions show a message box to the user when the function is executed? For example, when the user presses the button, and the function executes, if it exceeds the maximum number of iterations, the function should finish executing, and then a message box should show up warning the user that the function failed to converge. Furthermore, how can I implement such a thing without using UI code in the file with the solver source code? Make your solver return information about whether it converged on an answer or not: struct SolverResult { double finalValue; bool converged; }; Then, do extra checks when processing the result. If your result-processing code currently looks like this... void MainWindow::onSolverFinished(double finalValue) { this->doSomethingWith(finalValue); } ...now you can do extra checks: void MainWindow::onSolverFinished(const SolverResult &result) { if (result.converged) { // Yay, we found a solution! this->doSomethingWith(result.finalValue); } else { QMessageBox::warning(this, "No solution found", QStringLiteral("Failed to converge on a solution within %1 iterations").arg(m_maxIterations) ); } } Alternatively, you could adopt a convention like "Return NaN if it fails to converge", and show the QMessageBox inside if (qIsNan(finalValue))
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    24 Views
    No one has replied
  • How to replace to backspace ?

    Unsolved
    6
    0 Votes
    6 Posts
    707 Views
    S
    It is not so easy to decipher what the actual problem is. However, here is what I observe. We start with the following string: "123\n456\n789" If you just want to delete something from the string, you would replace it with an empty string. So, s.replace("456", ""); would yield "123\n\n789" This means, that this would print an empty line between 123 and 789. However, if you do s.replace("456", "\b"); you'll get "123\n\b\n789" I guess that like most people here I haven't ever used \b myself. Not all implementations that print out strings to the console (or wherever) might have an appropriate implementation of \b. Hence, this might vary. One possible implementation is that \b will indead delete the previous character when printed. In this case \n would be removed. This would result in the same output as "123\n789" However, another implementation might print line by line. So, when \b is encountered a new line has already begun. And on the new line there is nothing to delete. The command line is not a text editor where there is a document behind it and everything is rerendered when you change something. On the same line the implementation is quite simple: go back one character and replace it with blank (but keep the cursor at the same position). However, if the command line has to go back one line, it does not have the information stored where the previous line ended. It is quite impossible (without buffering) to go back to the previous line. After a new line you (most likely) have committed to what is printed on the screen (in most implementations). Note that you'll insert \b into the string. This does not delete the previous character inside the string. The string itself is just bytes and contains what you put in it. If you want to delete the full line containing 456, you should write s.replace("456\n", "");
  • lupdate and macros. using Q_OBJECT in your own macro.

    Unsolved lupdate macro qobject translation
    1
    0 Votes
    1 Posts
    169 Views
    No one has replied
  • Building and shipping QT 6.10 on RHEL 8

    Solved webengine qt6 building qt
    10
    0 Votes
    10 Posts
    4k Views
    D
    Thanks @SGaist. I agree that there can always be unknown unknowns in the deployments. I wanted to confirm that there are no obvious issues. I'll go ahead with the testing of this.
  • QSqlQuery in Qt6: in-place vs prepared

    Unsolved qsqlquery qsqlquerymodel qtableview
    26
    0 Votes
    26 Posts
    9k Views
    T
    @dviktor With the version shipped with debian trixie 11.8.6-MariaDB-0+deb13u1 , it works properly
  • QSqlTableModel Network Performance

    Solved
    22
    0 Votes
    22 Posts
    8k Views
    SGaistS
    Not three wrong ones, each has its use 😅 That said, you learned stuff on the way which are valuable You're welcome !
  • Future of non C++ backend languages and Qt frontend

    Unsolved
    6
    0 Votes
    6 Posts
    1k Views
    S
    @Gijs-Groote said in Future of non C++ backend languages and Qt frontend: What future plans does Qt group have with QtWidgets? I guess that most developers in this forum feel like QWidgets is mostly (but not fully) abandoned project. QML is continuously developed further, but QWidgets is stagnating. This might be related that for desktop applications you can use the open source license (only few are paying for a commercial license). QML is important for embedded, automotive, and mobile. For most (or all?) of these areas you have to buy licenses. So, this is where the money is. If you are a larger company and have dedicated designers, I would claim that QML is the better option (many designers can easily edit the design in QML or even use standard design tools). Few designers will be able to edit C++ code (in the case of QWidgets) to change the design.
  • 0 Votes
    10 Posts
    3k Views
    SGaistS
    @drmhkelley hi, Check that you did not disable Shadow builds in Qt Creator.
  • Assert in QTabWidgwt

    Unsolved
    5
    0 Votes
    5 Posts
    2k Views
    S
    @SGaist said in Assert in QTabWidgwt: It's not your code that is doubted, it is whether there is a mix between your application being built in release mode but using debug libraries when running or vice versa. Can you check whether you are using the libraries matching your application build type ? I use CMAKE to manage the dependencies, and do not add any lib manually. This issue just happened in Debug mode. I check (by my IDE , visual studio 2026 ) all libs used in my project , all of them are Debug mode. And i also check the libs in "Install directory", there is no problem either. I start the exe ( double click ) in install directory, it also has runtime crash with the message box "Debug error! xxx.exe abort() has been called ".