Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
84.0k Topics 460.1k Posts
Qt 6.11 is out! See what's new in the release blog
  • How add crosshair QtChart (with signed values)?

    Unsolved
    3
    0 Votes
    3 Posts
    2k Views
    G
    I recently tackled this problem for a project I'm working on. The solution was small enough that I don't mind sharing. See the results below: [image: f8e19694-93f1-456f-86da-2b505140e95d.png] I know this isn't styled exactly as your mockup, but hopefully it is enough to get you started. You can style as desired afterwards. My prototype was implemented right in the callout example. It's possible you won't need the QChartGlobal include or NAMESPACE macros in your adaptation. crosshairs.h #ifndef CROSSHAIRS_H #define CROSSHAIRS_H #include <QtCharts/QChartGlobal> #include <QtWidgets/QGraphicsItem> QT_CHARTS_BEGIN_NAMESPACE class QChart; QT_CHARTS_END_NAMESPACE QT_CHARTS_USE_NAMESPACE class Crosshairs { public: Crosshairs(QChart *chart); void updatePosition(QPointF position); private: QGraphicsLineItem *m_xLine, *m_yLine; QGraphicsTextItem *m_xText, *m_yText; QChart *m_chart; }; #endif // CROSSHAIRS_H crosshairs.cpp #include "crosshairs.h" #include <QtCharts/QChart> #include <QtGui/QPainter> #include <QtGui/QCursor> #include <QtGui/QTextDocument> QT_CHARTS_USE_NAMESPACE Crosshairs::Crosshairs(QChart *chart) : m_xLine(new QGraphicsLineItem(chart)), m_yLine(new QGraphicsLineItem(chart)), m_xText(new QGraphicsTextItem(chart)), m_yText(new QGraphicsTextItem(chart)), m_chart(chart) { m_xLine->setPen(QPen(Qt::red, 0.0)); m_yLine->setPen(QPen(Qt::red, 0.0)); m_xText->setZValue(11); m_yText->setZValue(11); m_xText->document()->setDocumentMargin(0); m_yText->document()->setDocumentMargin(0); m_xText->setDefaultTextColor(Qt::white); m_yText->setDefaultTextColor(Qt::white); } void Crosshairs::updatePosition(QPointF position) { QLineF xLine(position.x(), m_chart->plotArea().top(), position.x(), m_chart->plotArea().bottom()); QLineF yLine(m_chart->plotArea().left(), position.y(), m_chart->plotArea().right(), position.y()); m_xLine->setLine(xLine); m_yLine->setLine(yLine); QString xText = QString("%1").arg(m_chart->mapToValue(position).x()), yText = QString("%1").arg(m_chart->mapToValue(position).y()); m_xText->setHtml(QString("<div style='background-color: #ff0000;'>") + xText + "</div>"); m_yText->setHtml(QString("<div style='background-color: #ff0000;'>") + yText + "</div>"); m_xText->setPos(position.x() - m_xText->boundingRect().width() / 2.0, m_chart->plotArea().bottom()); m_yText->setPos(m_chart->plotArea().right(), position.y() - m_yText->boundingRect().height() / 2.0); if (!m_chart->plotArea().contains(position)) { m_xLine->hide(); m_xText->hide(); m_yLine->hide(); m_yText->hide(); } else { m_xLine->show(); m_xText->show(); m_yLine->show(); m_yText->show(); } } Declare a member variable in view.h and instantiate it in the constructor. m_crosshairs = new Crosshairs(m_chart); Then, update the crosshair's position from View::mouseMoveEvent m_crosshairs->updatePosition(event->pos()); Voila. Hope this helps!
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    2 Views
    No one has replied
  • Designing a simple project in QT Designer - question

    Solved
    6
    0 Votes
    6 Posts
    661 Views
    A
    Using the insight from SGaist I managed to get the results I wanted by defining a function called pressed that links to the pushButton. Based on the comboBox choosen, It sets the Text for a textBrowser to the needed information. Small snippet of the code below: def pressed(self): if self.comboBox.currentIndex() == 0: self.textBrowser.setText("Randon info about activity one.") Thank SGaist, I just needed another perspective.
  • QFileDialog open on top of windows

    Solved
    5
    0 Votes
    5 Posts
    1k Views
    M
    In result I use this: fileDialog = QFileDialog(self.ui) fileDialog.setWindowModality(QtCore.Qt.ApplicationModal) fileDialog.setOption(QFileDialog.DontUseNativeDialog)
  • QTimer and Time Slider and VideoPlayer Problem

    Unsolved
    5
    0 Votes
    5 Posts
    1k Views
    D
    @SGaist Hi, yes, I am currently testing it with sample videos found on the Internet Maybe VLC can be the alternative. My current solution is using a thread for the timer. To eliminate the timer's wrong timeout, I am checking the QDateTime::currentDateTime(); and the time of the previous timeout signal. With this, I made the synchronization between my time slider and the videos. I am just tuning the slider and all videos at the moment of play button is pressed. It is currently working, but I do not know if it is good or bad.
  • memory management

    Solved
    8
    0 Votes
    8 Posts
    2k Views
    ODБOïO
    hi Thank you very much for all your inputs @kshegunov said in memory management: Something I forgot to ask, why not keep the object list as a regular one (e.g. QList<QObject *>) and put the QVector/QList in the variant whenever you need to? You are right it much simpler to have a member QList<QObject *> and return QVariant list only when i need it. Thats what i did. Thank you
  • Qt Quick3D custom geometry from 3D array

    Unsolved
    1
    0 Votes
    1 Posts
    679 Views
    No one has replied
  • QTableWidget add parameters to slot

    Unsolved
    4
    0 Votes
    4 Posts
    1k Views
    JonBJ
    @Thomas-63 Sooner or later, you will need to change over to not use the auto-connect and do your own connect()s anyway. And use the new style, not the SIGNAL/SLOT() macros. And then you will be able to use lambdas and pass your own parameters. Sooner you do so, better it will be for you :)
  • Recover QPrintDialog range on linux.

    Unsolved
    1
    0 Votes
    1 Posts
    279 Views
    No one has replied
  • How to observe / debug "output to form" ?

    Unsolved
    2
    0 Votes
    2 Posts
    417 Views
    JonBJ
    @AnneRanch "In design mode" you are not running any code. There is no output. So nothing to observe.
  • How to get coordinates of text cursor and map to parent coordinates?

    Solved
    3
    0 Votes
    3 Posts
    775 Views
    I
    Thanks! I don't know how I overlooked that. It's obvious now that I know. =P (I think the problem was that I called dir() on the QRect object to see what it contained instead of looking at the QT reference, and it wasn't there. (I think I had also looked at the QT reference before that and saw top() but not topLeft()))
  • Rubber band changed the axis range like silly

    Unsolved
    6
    0 Votes
    6 Posts
    1k Views
    jsulmJ
    @firsnur96 @SGaist means a small application which demonstrates the issue you have, so others can reproduce it.
  • multi precise timer delay functions compare

    Solved
    9
    0 Votes
    9 Posts
    4k Views
    jeremy_kJ
    If high precision busy waiting is the goal, QDeadlineTimer is a better choice than QTimer.
  • 0 Votes
    9 Posts
    1k Views
    J
    ok thanks
  • QButtonBox problem with the button how do I know which one has been clicked

    Unsolved
    2
    0 Votes
    2 Posts
    528 Views
    JKSHJ
    @AI_Messiah said in QButtonBox problem with the button how do I know which one has been clicked: how do I know which one has been clicked Your slot has a QAbstractButton *button parameter that points to the button that was clicked. QButtonBox There is no class called "QButtonBox". Do you mean QButtonGroup or QDialogButtonBox? I want the entry to be changed with OK and close the dialog with Cancel If you meant QDialogButtonBox, it emits the accepted() signal when you click "OK", and emits the rejected() signal when you click "Cancel".
  • "Big Icons" on left side of edit screen ??

    Solved
    2
    0 Votes
    2 Posts
    407 Views
    JKSHJ
    @AnneRanch said in "Big Icons" on left side of edit screen ??: What is the official name of what appears to be standard "tab" implementation ? That's the Mode Selector ([1] at https://doc.qt.io/qtcreator/creator-quick-tour.html ) [image: qtcreator-breakdown.png] Why is "design" disabled ? "Design" opens Qt Designer. It is only applicable when you open a .ui file.
  • How to avoid repeated execution of loading Qlibrary?

    Unsolved
    23
    0 Votes
    23 Posts
    7k Views
    RogerBretonR
    Thank you all for your patient help. I'm putting QT on the backburner for now. Too bad. Such a nice environment.
  • Upgrading from qt 5.5.1 to qt 5.15.2

    Solved
    7
    0 Votes
    7 Posts
    3k Views
    A
    So it turns out that webengine was not getting build, thus that error above. For those having the same issue as me, try calling vcvarsall.bat with amd64_x86 as mentioned here: https://doc.qt.io/qt-5/qtwebengine-platform-notes.html
  • This topic is deleted!

    Moved Unsolved
    1
    0 Votes
    1 Posts
    18 Views
    No one has replied
  • Items of QListWidget are greyed out

    Solved
    3
    0 Votes
    3 Posts
    827 Views
    D
    @JonB Thank you for you response. I finally figured it out, there was a QSplitter surrounding the QTabWidget and i tought i could prevent it from being resize by calling setEnabled(false) directly on it. I found a solution on Stack Overflow : https://stackoverflow.com/a/9224819/10525519 .