Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.6k Topics 457.5k Posts
  • How to check if MySQL connection is alive?

    Solved mysql connect alive
    2
    0 Votes
    2 Posts
    438 Views
    SGaistS
    Hi, One possible thing you could try is grab the database handle and use the mysql_ping method. Haven't done it myself so I can't guarantee
  • QHeaderView background color for each section

    Unsolved
    8
    0 Votes
    8 Posts
    1k Views
    jeremy_kJ
    @rudag said in QHeaderView background color for each section: Tried your setHeaderData() and didn't work. I really would like a solution without subclass. I tried like bellow and background is okay, but it doesn't show the text. Did you try the full and unmodified program? That suggests that you've found a bug in Qt. If it was instead adapted into a non-working program, that doesn't tell me anything meaningful. The snippets of the nonworking program posted so far aren't enough to work with.
  • QSerialPort not working asynchronously under Windows

    Solved
    5
    0 Votes
    5 Posts
    526 Views
    JonBJ
    @fe-sc I do respect what you are saying and your decision. I would just say that I would expect a program running with Qt 5.12.5 to move to 5.15.x without any source changes or altered behaviour, just taking advantage of the bug fixes. But if you have it working now that is good.
  • QScxmlStateMachine How to Modify the History State?

    Unsolved
    2
    0 Votes
    2 Posts
    195 Views
    SGaistS
    Hi and welcome to devnet, I would venture that it is pretty unlikely as the very goal of the history state is to come back to a known state. If you want to do something custom, you better implement your own "history" state.
  • Problem with ContextMenu

    Unsolved
    24
    0 Votes
    24 Posts
    5k Views
    C
    @Kevin-Hoang That event does not get fired. See the comments above.
  • QPrinterInfo::availablePrinterNames() returns empty list

    Unsolved
    7
    0 Votes
    7 Posts
    608 Views
    H
    @Christian-Ehrlicher cups is found, I see it building printer support plugins. My problem is that printers list in my app is still empty. Right now I found out it might be packaging problem (I assume there must be MyApp/plugins/printsupport/something, which I don't have right now). Edit: I did rebuilt Qt already with libcups2-dev installed, sorry for misunderstanding (I did that after first answer).
  • QDir::exists() returns false while directory exists

    Solved
    6
    0 Votes
    6 Posts
    733 Views
    Christian EhrlicherC
    @Aleksey_K said in QDir::exists() returns false while directory exists: thought QDir should understand QUrl. Where did you read this? A local directory is something totally different than an url...
  • white text on white background in qt designer

    Unsolved
    7
    0 Votes
    7 Posts
    735 Views
    jsulmJ
    @ReZare said in white text on white background in qt designer: where can I download the latest? Searching a bit you will find: https://www.qt.io/download-qt-installer-oss
  • Struggling with basic class structure

    Unsolved
    7
    0 Votes
    7 Posts
    737 Views
    S
    @Chris-Kawa said in Struggling with basic class structure: They are not really meant to be replacement for simple getters and setters Agreed. You are right about the QAbstractItemModel. I was thinking more along the lines of simple UI elements connecting valueChanged(...) signals and setValue(...) slots or even QPushButton::pressed(). For those I advocate to just connect those signals and slots. E.g.SettingsWidget might connect the slots of individual UI elements to its own slots (like countChanged(int), nameChanged(QString), ...) which the MainWindow can then connect to the PlotModel.
  • How to Implement Acrylic Effect in Qt UI?

    Unsolved
    3
    0 Votes
    3 Posts
    452 Views
    Pl45m4P
    @froxy IIRC there was a similar post + solution few years ago here in the forum... Maybe you are able to find it via search function.
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    8 Views
    No one has replied
  • Cannot make QGraphicsTextItem both in center of the scene and with supported word wrap

    Unsolved
    5
    0 Votes
    5 Posts
    520 Views
    S
    @SGaist hi, I managed to fix it but my solution looks very over-engineered to me... I've also tried your suggestion but by itself it does not really work as intended. def _center_text(self): width = max(0, self.viewport().width() - 20) doc = self._text.document() doc.setTextWidth(width) self.centerOn(self._text) This does not really work because the problem is that the text itself is not centered. So, the text item is occupying width of whole viewport but text is on the left anyway, though wrap works correctly. def _center_text(self): width = max(0, self.viewport().width() - 20) doc = self._text.document() doc.setTextWidth(-1) natural_width = doc.idealWidth() text_width = min(natural_width, width) doc.setTextWidth(text_width) self.centerOn(self._text) This works almost as intended, but the wrapped text is again on the left. So the text is in the center when it has only one line, the effect is broken when wrap is introduced. def _center_text(self): width = max(0, self.viewport().width() - 20) doc = self._text.document() doc.setTextWidth(-1) natural_width = doc.idealWidth() text_width = min(natural_width, width) doc.setTextWidth(text_width) self.centerOn(self._text) cursor = QTextCursor(doc) block_format = QTextBlockFormat() block_format.setAlignment(Qt.AlignCenter) cursor.select(QTextCursor.Document) cursor.mergeBlockFormat(block_format) These crazy additional lines which I barely found make the centered text even for the wrapped version. However, I still had some weird effect in my real app when first position of the text was wrong, but after any resize it would normalize. This is most likely because the widget there is not visible by default so some sizes are not properly calculated. I am not sure how to solve this with centerOn. Tried several things but problem persisted or the location broke completely. So I returned to setPos and even had to add setSceneRect on top of that. With this solution I get correct behavior at all time: different sizes, hiding/showing widget, switching between tabs... Amount of code required just for centering the text is crazy though, so if someone has improvement ideas, they are welcome here. def _center_text(self): width = max(0, self.viewport().width() - 20) height = max(0, self.viewport().height() - 20) self._scene.setSceneRect(QRectF(0, 0, width, height)) doc = self._text.document() doc.setTextWidth(-1) natural_width = doc.idealWidth() text_width = min(natural_width, width) doc.setTextWidth(text_width) cursor = QTextCursor(doc) block_format = QTextBlockFormat() block_format.setAlignment(Qt.AlignCenter) cursor.select(QTextCursor.Document) cursor.mergeBlockFormat(block_format) text_rect = self._text.boundingRect() scene_rect = self._scene.sceneRect() center_x = scene_rect.center().x() - text_rect.width() / 2 center_y = scene_rect.center().y() - text_rect.height() / 2 self._text.setPos(center_x, center_y)
  • Has anyone tried Qt Speech?

    Unsolved
    10
    0 Votes
    10 Posts
    990 Views
    C
    I tried it a while ago, when I was first starting with Qt...and yeah, doesn't sound so great. The reason why is already explained by SGaist. I tried a lot of options on Linux (KDE Neon, Fedora), and RHVoice seemed to sound best, but still not quite there, and I'm not sure how are things now, but, if it helps: https://stackoverflow.com/questions/76094006/how-to-use-rhvoice-via-speech-dispatcher-in-qt Try different voices and voice settings, or look for other options, perhaps new ones exist now. I'm also interested to see if anyone has suggestions.
  • Simulating a joystick

    Solved
    2
    0 Votes
    2 Posts
    302 Views
    serkan_trS
    I made a joystick as I wanted. You can check the code on this page.
  • Reading data from serial port

    Solved
    6
    0 Votes
    6 Posts
    641 Views
    serkan_trS
    I made the necessary modifications. In this part, I monitor the port at specific intervals and close the port if there is a change in the list of connected cards. This ensures that the port automatically connects and closes when the card is removed. My code is as follows, and you can access it on this GitHub page.
  • Proper way to remove connections from a QGraphicsScene

    Unsolved
    11
    0 Votes
    11 Posts
    1k Views
    JonBJ
    @james-b-s Then I think you have a problem! I believe to disconnect a lambda explicitly (if you cannot introduce a slot object) you need to store the result of the connect() and pass that to disconnect(). But presumably you cannot do that either if the code you show is untouchable third-party? P.S. If you're interested in a discussion on this slot-lambda-functor-without-slot-object destruction problem read through https://interest.qt-project.narkive.com/AiSB9wkP/who-disconnects-lambda-expression-slots from when it was raised 12 years ago :)
  • Implement a Custom Protocol on Mac

    Unsolved mac os qtwidgets
    14
    0 Votes
    14 Posts
    4k Views
    S
    The Implementation to handle a custom Protocol in the Application does no more work in Qt 6.8.2 as described above (only the C++ programming part, the other stuff - Info.plist etc. remains unchanged) The correct way to implement such a handler is to use void QDesktopServices::setUrlHandler() See https://doc.qt.io/qt-6/qdesktopservices.html#setUrlHandler This paragraph also describes how to set Info.plist etc... This most likely also would have worked in 6.5.3 - why did I never find it? For Windows all of this works quite differently. Registering works through well known registry entries: [HKEY_CLASSES_ROOT\myprotocol] "URL Protocol"="" [HKEY_CLASSES_ROOT\myprotocol\shell] [HKEY_CLASSES_ROOT\myprotocol\shell\open] [HKEY_CLASSES_ROOT\myprotocol\shell\open\command] @="\"path to application.exe" \"%1\" This will just start a new instance of the application with the custom protocols URL as first parameter %1. Its the applications responsibility to handle that correctly (i.e. call a existing instance via a QLocalSocket etc.
  • 0 Votes
    6 Posts
    772 Views
    SGaistS
    You're welcome ! Since you have it working now, please mark the thread as solved using the "Topic Tools" button or the three dotted menu beside the answer you deem correct so other forum users may know a solution has been found :-)
  • qformlayout cleanup/repaint after takerow()

    Solved qformlayout takerow qt 5.14
    5
    0 Votes
    5 Posts
    436 Views
    SGaistS
    Oh ! My bad ! I meant that takeRow would allow the OP to not have to recreate the row content every time.
  • Great job updating the Qt docs with a sidebar

    Unsolved
    6
    7 Votes
    6 Posts
    598 Views
    A
    In my case, I would like the Qt version documentation popup to always be visible, or even better, to be set only once, because every time I need to look for something, I have to change the Qt version.