Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.5k Topics 457.3k Posts
  • Why QT C++ application get crash ?

    Solved
    4
    0 Votes
    4 Posts
    484 Views
    Christian EhrlicherC
    @Qt-embedded-developer said in Why QT C++ application get crash ?: QSharedPointer<QQmlApplicationEngine>::~QSharedPointer You were informed about the problems when using automatic pointers with Qt objects in your last question: https://forum.qt.io/topic/154869/what-is-difference-between-std-unique_ptr-v-s-std-make_unique?_=1709130823393
  • QDesignerCustomWidgetInterface name in palette

    Unsolved
    3
    0 Votes
    3 Posts
    228 Views
    Andy314A
    @Pl45m4 said in QDesignerCustomWidgetInterface name in palette: @Andy314 I don't quite understand what you are asking for. I mean, if you look at the Analog Clock example, it's done like this: QString AnalogClockPlugin::name() const { return u"AnalogClock"_s; } Can't you just put your desired name there (and name your class the same way)? Its more for esthetic than functionality: My Class ist "AdvancedComboBox" but I will see in the Designer palette somthing like " Combo Box (advanced). Similar to to the standard widgets: For class QComboBox I see in the designer the text "Combo Box".
  • qt_add_dbus_interface output namespace errors

    Unsolved
    2
    0 Votes
    2 Posts
    169 Views
    L
    I found https://develop.kde.org/docs/features/d-bus/using_custom_types_with_dbus/ which explains it. When accessing functions that expose custom types you have to go through manual steps to include and expose these to the QMetaType system. This is not going to be practical for my purpose.
  • Installer exe

    Solved
    4
    0 Votes
    4 Posts
    381 Views
    R
    @Rockerz I copied and pasted But i'm getting The procedure entry point_Z20qResourceFeatureZlib could not be located in the dynamic link library
  • Question on model/view design: ListView with model that does not own the data

    Solved
    3
    0 Votes
    3 Posts
    220 Views
    C
    If D can issue signals then those signals can trigger necessary actions in M that will, in turn, updates in all attached views (can be more than one). At the coarse level trigger something like: void M::dChanged() { beginResetModel(); // refresh/discard any cached internal state M has about D endResetModel() } If you get D to issue finer grained signals e.g., rowDeleted(uuid) , then you may be able to do finer things within M in response. This is desirable from a user view perspective.
  • 0 Votes
    2 Posts
    544 Views
    Chris KawaC
    TL;DR; Add #include "ui_Task.h" in your Task.cpp file. Longer explanation - the uic tool takes the Task.ui file and generates ui_Task.h header, which contains the definition for the Ui::Task class. This header is to be included in your Task.cpp file so that you can use it to initialize your ui by first creating an instance of that class (it's the new Ui::Task line that gives you the error about incomplete type) and then calling ui->setupUi(this) on it. Compare that with the wizard generated code - see the #include "ui_Mainwindow.h" line in the Mainwindow.cpp file.
  • 0 Votes
    4 Posts
    722 Views
    Christian EhrlicherC
    @Qt-embedded-developer I really wonder what's so hard looking into the documentation ... esp. since you would get an answer much earlier. RTM: https://doc.qt.io/qt-6/eventsandfilters.html#event-filters
  • ERROR: copy relocation against non-copyable protected symbol

    Solved
    5
    0 Votes
    5 Posts
    3k Views
    O
    I found a add_target_link error in one of the sub-folder CMakeLists.txt file... Stupid me. Compiles better now. Could someone explain why the new flag -fPIC is needed in Qt6 and was not in Qt5? And is not needed in other projects ? Thx. It's otherwise resolved.
  • How to use QHttpServer missing handler?

    Unsolved
    4
    0 Votes
    4 Posts
    638 Views
    JonBJ
    @Tarae Oh, you mean just you want to know what to put in the body of missingHandler() to not cause that. I did not understand that was your issue from the question. Since Content-type will be "application/x-empty" I don't suppose just removing responder.writeBody() makes it any better? I take it you know what curl will show. Anyway I leave it to you now, sorry.
  • Please assist the non-expert.

    Unsolved
    7
    0 Votes
    7 Posts
    567 Views
    B
    @Ronel_qtmaster , Thanks. I think they are and I'll check on that as I head over to a Gnu Radio forum.
  • Qt6 comparing "\\" to QChar not working anymore

    Unsolved
    3
    0 Votes
    3 Posts
    377 Views
    C
    @Christian-Ehrlicher Thanks! That solved it
  • Auto-scrolling on dragging an item in QGraphicsScene

    Solved
    4
    0 Votes
    4 Posts
    653 Views
    R
    @Robert-Hairgrove It seems that the scroll bars were sometimes lagging behind after moving the objects; the objects were not really clipped, but the view was not completely scrolled which made it look like they were clipped. Here is my current changed version of diagramscene.h and diagramscene.cpp including additional headers which needed #include directives: diagramscene.h: /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** BSD License Usage ** Alternatively, you may use this file under the terms of the BSD license ** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of The Qt Company Ltd nor the names of its ** contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #ifndef DIAGRAMSCENE_H #define DIAGRAMSCENE_H #include "diagramitem.h" #include "diagramtextitem.h" #include <QGraphicsScene> QT_BEGIN_NAMESPACE class QGraphicsSceneMouseEvent; class QMenu; class QPointF; class QGraphicsLineItem; class QFont; class QGraphicsTextItem; class QColor; QT_END_NAMESPACE #define DIAGRAMSCENE_BORDER_WIDTH 10 //! [0] class DiagramScene : public QGraphicsScene { Q_OBJECT public: enum Mode { InsertItem, InsertLine, InsertText, MoveItem }; explicit DiagramScene(QMenu *itemMenu, QObject *parent = nullptr); QFont font() const { return myFont; } QColor textColor() const { return myTextColor; } QColor itemColor() const { return myItemColor; } QColor lineColor() const { return myLineColor; } void setLineColor(const QColor &color); void setTextColor(const QColor &color); void setItemColor(const QColor &color); void setFont(const QFont &font); public slots: void setMode(Mode mode); void setItemType(DiagramItem::DiagramType type); void editorLostFocus(DiagramTextItem *item); signals: void itemInserted(DiagramItem *item); void textInserted(QGraphicsTextItem *item); void itemSelected(QGraphicsItem *item); protected: void mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) override; void mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) override; void mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) override; private: bool isItemChange(int type) const; // Added:----- void adjustDragPositions(QGraphicsView *pv, qreal border = DIAGRAMSCENE_BORDER_WIDTH); //------------ DiagramItem::DiagramType myItemType; QMenu *myItemMenu; Mode myMode; bool leftButtonDown; QPointF startPoint; QGraphicsLineItem *line; QFont myFont; DiagramTextItem *textItem; QColor myTextColor; QColor myItemColor; QColor myLineColor; }; //! [0] #endif // DIAGRAMSCENE_H diagramscene.cpp: /**************************************************************************** ** ** Copyright (C) 2016 The Qt Company Ltd. ** Contact: https://www.qt.io/licensing/ ** ** This file is part of the examples of the Qt Toolkit. ** ** $QT_BEGIN_LICENSE:BSD$ ** Commercial License Usage ** Licensees holding valid commercial Qt licenses may use this file in ** accordance with the commercial license agreement provided with the ** Software or, alternatively, in accordance with the terms contained in ** a written agreement between you and The Qt Company. For licensing terms ** and conditions see https://www.qt.io/terms-conditions. For further ** information use the contact form at https://www.qt.io/contact-us. ** ** BSD License Usage ** Alternatively, you may use this file under the terms of the BSD license ** as follows: ** ** "Redistribution and use in source and binary forms, with or without ** modification, are permitted provided that the following conditions are ** met: ** * Redistributions of source code must retain the above copyright ** notice, this list of conditions and the following disclaimer. ** * Redistributions in binary form must reproduce the above copyright ** notice, this list of conditions and the following disclaimer in ** the documentation and/or other materials provided with the ** distribution. ** * Neither the name of The Qt Company Ltd nor the names of its ** contributors may be used to endorse or promote products derived ** from this software without specific prior written permission. ** ** ** THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ** "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT ** LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR ** A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT ** OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, ** DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY ** THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT ** (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE ** OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE." ** ** $QT_END_LICENSE$ ** ****************************************************************************/ #include "diagramscene.h" #include "arrow.h" #include <QApplication> #include <QGraphicsSceneMouseEvent> #include <QGraphicsItem> #include <QGraphicsView> #include <QScrollBar> #include <QTextCursor> //! [0] DiagramScene::DiagramScene(QMenu *itemMenu, QObject *parent) : QGraphicsScene(parent) { myItemMenu = itemMenu; myMode = MoveItem; myItemType = DiagramItem::Step; line = nullptr; textItem = nullptr; myItemColor = Qt::white; myTextColor = Qt::black; myLineColor = Qt::black; } //! [0] //! [1] void DiagramScene::setLineColor(const QColor &color) { myLineColor = color; if (isItemChange(Arrow::Type)) { Arrow *item = qgraphicsitem_cast<Arrow *>(selectedItems().first()); item->setColor(myLineColor); update(); } } //! [1] //! [2] void DiagramScene::setTextColor(const QColor &color) { myTextColor = color; if (isItemChange(DiagramTextItem::Type)) { DiagramTextItem *item = qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first()); item->setDefaultTextColor(myTextColor); } } //! [2] //! [3] void DiagramScene::setItemColor(const QColor &color) { myItemColor = color; if (isItemChange(DiagramItem::Type)) { DiagramItem *item = qgraphicsitem_cast<DiagramItem *>(selectedItems().first()); item->setBrush(myItemColor); } } //! [3] //! [4] void DiagramScene::setFont(const QFont &font) { myFont = font; if (isItemChange(DiagramTextItem::Type)) { QGraphicsTextItem *item = qgraphicsitem_cast<DiagramTextItem *>(selectedItems().first()); //At this point the selection can change so the first selected item might not be a DiagramTextItem if (item) item->setFont(myFont); } } //! [4] void DiagramScene::setMode(Mode mode) { myMode = mode; } void DiagramScene::setItemType(DiagramItem::DiagramType type) { myItemType = type; } //! [5] void DiagramScene::editorLostFocus(DiagramTextItem *item) { QTextCursor cursor = item->textCursor(); cursor.clearSelection(); item->setTextCursor(cursor); if (item->toPlainText().isEmpty()) { removeItem(item); item->deleteLater(); } } //! [5] //! [6] void DiagramScene::mousePressEvent(QGraphicsSceneMouseEvent *mouseEvent) { if (mouseEvent->button() != Qt::LeftButton) return; DiagramItem *item; switch (myMode) { case InsertItem: item = new DiagramItem(myItemType, myItemMenu); item->setBrush(myItemColor); addItem(item); item->setPos(mouseEvent->scenePos()); emit itemInserted(item); break; //! [6] //! [7] case InsertLine: line = new QGraphicsLineItem(QLineF(mouseEvent->scenePos(), mouseEvent->scenePos())); line->setPen(QPen(myLineColor, 2)); addItem(line); break; //! [7] //! [8] case InsertText: textItem = new DiagramTextItem(); textItem->setFont(myFont); textItem->setTextInteractionFlags(Qt::TextEditorInteraction); textItem->setZValue(1000.0); connect(textItem, &DiagramTextItem::lostFocus, this, &DiagramScene::editorLostFocus); connect(textItem, &DiagramTextItem::selectedChange, this, &DiagramScene::itemSelected); addItem(textItem); textItem->setDefaultTextColor(myTextColor); textItem->setPos(mouseEvent->scenePos()); emit textInserted(textItem); //! [8] //! [9] default: ; } QGraphicsScene::mousePressEvent(mouseEvent); } //! [9] //! [10] void DiagramScene::mouseMoveEvent(QGraphicsSceneMouseEvent *mouseEvent) { static bool IN_EVENT = false; // Find the current view: QGraphicsView* pv = nullptr; if (mouseEvent->widget()) pv = qobject_cast<QGraphicsView *>(mouseEvent->widget()->parentWidget()); if (!IN_EVENT) { if (myMode == InsertLine && line != nullptr) { QLineF newLine(line->line().p1(), mouseEvent->scenePos()); line->setLine(newLine); } else if (myMode == MoveItem) { //-------------------------------------- if (pv) { IN_EVENT = true; QGraphicsScene::mouseMoveEvent(mouseEvent); adjustDragPositions(pv); IN_EVENT = false; } //-------------------------------------- } } } //! [10] //! [11] void DiagramScene::mouseReleaseEvent(QGraphicsSceneMouseEvent *mouseEvent) { if (line != nullptr && myMode == InsertLine) { QList<QGraphicsItem *> startItems = items(line->line().p1()); if (startItems.count() && startItems.first() == line) startItems.removeFirst(); QList<QGraphicsItem *> endItems = items(line->line().p2()); if (endItems.count() && endItems.first() == line) endItems.removeFirst(); removeItem(line); delete line; //! [11] //! [12] if (startItems.count() > 0 && endItems.count() > 0 && startItems.first()->type() == DiagramItem::Type && endItems.first()->type() == DiagramItem::Type && startItems.first() != endItems.first()) { DiagramItem *startItem = qgraphicsitem_cast<DiagramItem *>(startItems.first()); DiagramItem *endItem = qgraphicsitem_cast<DiagramItem *>(endItems.first()); Arrow *arrow = new Arrow(startItem, endItem); arrow->setColor(myLineColor); startItem->addArrow(arrow); endItem->addArrow(arrow); arrow->setZValue(-1000.0); addItem(arrow); arrow->updatePosition(); } } //! [12] //! [13] line = nullptr; QGraphicsScene::mouseReleaseEvent(mouseEvent); } //! [13] //! [14] bool DiagramScene::isItemChange(int type) const { const QList<QGraphicsItem *> items = selectedItems(); const auto cb = [type](const QGraphicsItem *item) { return item->type() == type; }; return std::find_if(items.begin(), items.end(), cb) != items.end(); } //! [14] void DiagramScene::adjustDragPositions(QGraphicsView *pv, qreal border) { Q_ASSERT_X(pv, __func__, "Pointer to view was NULL."); if (border < DIAGRAMSCENE_BORDER_WIDTH) border = DIAGRAMSCENE_BORDER_WIDTH; // Get the selected items: QList<QGraphicsItem*> selected = selectedItems(); if (selected.isEmpty()) return; QGraphicsItemGroup * gp = createItemGroup(selected); if (gp) { QRectF br = gp->boundingRect(); qreal diffX = 0; qreal diffY = 0; // check left border: if (br.x() < border) { diffX = border - br.x(); } // check right border: if (br.x()+br.width() > this->width() - border) { Q_ASSERT_X(diffX == 0, __func__, "diffX was already set for left border " "adjustment."); diffX = -((br.x() + br.width()) - (width() - border)); } // check top border: if (br.y() < border) { diffY = border - br.y(); } // check bottom border: if (br.y()+br.height() > this->height() - border) { Q_ASSERT_X(diffY == 0, __func__, "diffY was already set for top border " "adjustment."); diffY = -((br.y() + br.height()) - (height() - border)); } if (diffX == 0.0 && diffY == 0.0) { pv->ensureVisible(gp, border, border); } else { // move the group: gp->moveBy(diffX, diffY); QScrollBar *sb = nullptr; if (diffX) { // Scroll all the way to the left or right // depending on whether diffX is positive or negative: sb = pv->horizontalScrollBar(); if (sb) { if (diffX > 0) { // we adjusted the left: sb->setValue(sb->minimum()); } else { // we adjusted the right: sb->setValue(sb->maximum()); } } } if (diffY) { // Scroll all the way to the top or bottom // depending on whether diffX is positive or negative: sb = pv->verticalScrollBar(); if (sb) { if (diffY > 0) { // we adjusted the top: sb->setValue(sb->minimum()); } else { // we adjusted the bottom: sb->setValue(sb->maximum()); } } } QApplication::processEvents(); } destroyItemGroup(gp); } } You will notice the extra code in DiagramScene::adjustDragPosition() which adjusts the scroll factor if needed, then calls QApplication::processEvents() to ensure that everything runs smoothly.
  • Canvas QT?

    Solved
    3
    0 Votes
    3 Posts
    415 Views
    P
    @Pl45m4 Thank you very much, all working! Appriciate your help:)
  • This topic is deleted!

    Unsolved
    2
    0 Votes
    2 Posts
    37 Views
  • Issue with Text Rendering Length Differences Using QPainter

    Solved
    7
    2 Votes
    7 Posts
    926 Views
    H
    Thanks for all the input!
  • 0 Votes
    3 Posts
    517 Views
    L
    @ChrisW67 Thanks for your response! Using Qt::FramelessWindowHint flags can help me in my case. But for further understanding, in case I want to record other apps then I have to remove its header section (such as the OBS header in above picture), I wonder If I could set this similar flags to CapturableWindow when I get it from capturableWindows(). Or QWindowCapture, QMediaRecorder had the other ways to help me with this? Please feel free to share, I’m grateful.
  • QTextEdit does not work properly when pasting rich text

    Unsolved
    1
    0 Votes
    1 Posts
    196 Views
    No one has replied
  • What is the best startegy for running one-off short tasks concurrently

    Unsolved
    6
    0 Votes
    6 Posts
    888 Views
    J
    So I found a Stack Overflow post that claims that QtConcurrent is a namespace, not a class and it is not implementable in Python, since it is template-based and templates are a C++ feature, therefore, the aforementioned Python documentation on how to use it is just auto-generated garbage and none of it actually exists in Python. Am I misunderstanding it? I suppose I am stuck to using QThread for every minor thing.... https://stackoverflow.com/questions/32378719/qtconcurrent-in-pyside-pyqt
  • How to avoid QWidget show the default background before paintEvent be called

    Unsolved
    7
    0 Votes
    7 Posts
    503 Views
    W
    @JoeCFD oh, I am not a touch screen. It is a pc with a monitor.
  • updating Chart

    Unsolved
    3
    0 Votes
    3 Posts
    309 Views
    J
    using a one shot timer works, thanks