Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
82.3k Topics 450.1k Posts
  • Qt UI Scale Problem

    Unsolved
    2
    0 Votes
    2 Posts
    50 Views
    Christian EhrlicherC

    Use layouts: https://doc.qt.io/qt-6/layout.html

  • Main Window Not Redrawing Until Clicked

    Unsolved
    4
    0 Votes
    4 Posts
    71 Views
    Christian EhrlicherC

    @Calvin-H-C said in Main Window Not Redrawing Until Clicked:

    Yes, the signal is emitted with this:

    This is not what the documentation tells you what has to be emitted when data in the model changes. Please read and follow the documentation. There are also enough examples out there.

  • QMediaPlayer and QIODevice, how to handle stalling media

    Unsolved
    5
    0 Votes
    5 Posts
    95 Views
    B

    @csab6597 That's a sad news, then I think you need to dig into Qt's internal code to find out.

    From a quick search for the string StalledMedia in the source codes of QtMultimedia, I guess not all the mediaplayer controls of the backends in the plugins would trigger this state, every backend handles it in its own way.
    cb581318-ee2f-459e-8c93-a684f51845f7png

    As for atEnd(), it does get called by some backends for example ffmpeg or gstreamer:

    // qtmultimedia/src/plugins/multimedia/ffmpeg/playbackengine/qffmpegmediadataholder.cpp static int readQIODevice(void *opaque, uint8_t *buf, int buf_size) { auto *dev = static_cast<QIODevice *>(opaque); if (dev->atEnd()) return AVERROR_EOF; return dev->read(reinterpret_cast<char *>(buf), buf_size); } // qtmultimedia/src/plugins/multimedia/gstreamer/common/qgstappsrc.cpp void QGstAppSrc::pushData() { ...... qCDebug(qLcAppSrc) << "pushData" << (m_stream ? m_stream : nullptr) << m_buffer.size(); if ((m_stream && m_stream->atEnd())) { eosOrIdle(); qCDebug(qLcAppSrc) << "end pushData" << (m_stream ? m_stream : nullptr) << m_buffer.size(); return; } ...... }

    So I think it does need to be reimplemented but maybe it is not enough.
    Well since I have no experience in this kind of case that's all what I can find now.

  • Question about overlay

    Unsolved
    3
    0 Votes
    3 Posts
    79 Views
    A

    I agree with @Pl45m4.

    Show us the code.

  • 2 Votes
    4 Posts
    195 Views
    V

    @devMiyax you're not on Pi, so I doubt it's the same issue.

  • Initializing a custom QSettings file

    Solved
    6
    0 Votes
    6 Posts
    106 Views
    B

    Actually I've learned a few things better here in a couple of posts. For my application and this class I did not need to inherit QObject or use Q_OBJECT at all. Indeed, I didn't need to save 'value' at all. I just needed to initialize settings properly. I thank you for your comments.

  • QSqlQuery exec returns false

    Solved
    9
    0 Votes
    9 Posts
    121 Views
    JonBJ

    @Yihua-Liu
    Since I asked and you said SELECT 0 does not even work you can forget everything else.

    I suspect you now need someone else to try with your version of Qt and of the Oracle client. If you can try a different version of Qt and/or a different version of Oracle client (I don't know how that works) that would be great. Otherwise you had better say exactly how you got your Qt (e.g. did you compile it yourself? with what config?) and similarly for whatever the Qt-to-Oracle library/driver is?

  • Creating an OPCUA connection to QT

    Unsolved
    2
    0 Votes
    2 Posts
    78 Views
    N

    Dont know if it helps under Debian i did it with the ninja build tool:

    sudo apt install openssl libssl-dev libmbedtls-dev libmbedtls14t64 ninja-build cd <QT_DIR>/<QT_VERSION>/Src/qtopcua # if qt opcua folder not there: cd <QT_DIR>/<QT_VERSION>/Src/ git clone https://code.qt.io/qt/qtopcua.git cd qtopcua git checkout <QT_VERSION> mkdir build && cd build <QT_DIR>/<QT_VERSION>/gcc_64/bin/qt-cmake -GNinja .. # To build the official Qt OPC UA examples: -DQT_BUILD_EXAMPLES=ON. ninja sudo ninja install
  • Qt building from sources - xcb dependencies

    Solved
    22
    0 Votes
    22 Posts
    692 Views
    MasterQM

    Hi,

    last update!

    After a break due to broken hardware I have started from scratch and now all is running fine.

    It seems that I previoulsy had used (by accident) an outdated compiler, gcc-7 instead of gcc-14.

  • 0 Votes
    7 Posts
    133 Views
    V

    @Bonnie Well,I made a simple method to normalize the level from 0 to 100,override function writeData from QBuffer

    qint64 AudioIODevice::writeData(const char* data, qint64 len) { QMutexLocker locker(&mutex); //recordedData->append(data, len); // Use QAudioFormat to handle audio data // int sampleSize = this->format.sampleFormat(); int sampleSize = format.sampleFormat(); QAudioFormat::SampleFormat sampleType = format.sampleFormat(); int channelCount = format.channelCount(); int bytesPerSample = sampleSize; double rmsValue = 0; int sampleCount = len / bytesPerSample; if (sampleType == QAudioFormat::Int16) { // Assume 16-bit signed integer (may need to adjust based on actual situation) const qint16* samples = reinterpret_cast<const qint16*>(data); qint64 sum = 0; for (int i = 0; i < sampleCount; ++i) { qint16 sampleValue = qFromLittleEndian<qint16>(samples[i]); sum += sampleValue * sampleValue; } rmsValue = std::sqrt(static_cast<double>(sum) / sampleCount) / 32768.0; } else if (sampleType == QAudioFormat::Int32) { // Assume 16-bit unsigned integer const quint16* samples = reinterpret_cast<const quint16*>(data); qint64 sum = 0; for (int i = 0; i < sampleCount; ++i) { quint16 sampleValue = qFromLittleEndian<quint16>(samples[i]); // Shift the sample value to center it at 0 int value = static_cast<int>(sampleValue) - 32768; sum += value * value; } rmsValue = std::sqrt(static_cast<double>(sum) / sampleCount) / 32768.0; } else if (sampleType == QAudioFormat::Float) { // Assume 32-bit floating point const float* samples = reinterpret_cast<const float*>(data); double sum = 0; for (int i = 0; i < sampleCount; ++i) { float sampleValue = samples[i]; sum += sampleValue * sampleValue; } rmsValue = std::sqrt(sum / sampleCount); } else { // Handle other data types return len; } // Prevent negative infinity in logarithmic calculation if (rmsValue < 1e-10) { rmsValue = 1e-10; } // Convert RMS value to decibels double dbValue = 20 * std::log10(rmsValue); // Define minimum and maximum decibel values for normalization constexpr double minDb = -60.0; constexpr double maxDb = 0.0; // Normalize decibel value to 0 - 1 range double normalizedVolume = (dbValue - minDb) / (maxDb - minDb); // Limit to 0 - 1 range normalizedVolume = clamp(normalizedVolume, 0.0, 1.0); // Convert to 0 - 100 range double volume = normalizedVolume * 100; // Emit volume signal emit sig_volumeChanged(volume); return QBuffer::writeData(data, len);; }
  • qt6 qt creator acceptTouchEvents on x11 ubuntu

    Unsolved
    2
    0 Votes
    2 Posts
    38 Views
    A

    Try add Qt::Window attribute in addition to AcceptTouchEvents

  • How to load PLY file in QT,C++, QML

    Unsolved
    3
    0 Votes
    3 Posts
    85 Views
    T

    Hi Thanks for your help.

    @Pl45m4 said in How to load PLY file in QT,C++, QML:

    Took me 5 seconds to find this topic:

    https://forum.qt.io/topic/94131/how-to-load-ply-content-properly

    So this is using QWidget to render UI. I am not sure if I can use it in QML project. Can I ?

    @Pl45m4 said in How to load PLY file in QT,C++, QML:

    And 1 more minute to find this note in the documentation of Qt 3D's QMesh:

    I will try to see if I can use Mesh in QML to render PLY file.

    @Pl45m4 said in How to load PLY file in QT,C++, QML:

    Seems like it's not possible with QtQuick3D to directly render .ply file content, but there is a console tool to convert the output you get from Blender, 3DS Max or Maya into QML usable files and render it...
    This also includes .ply files.

    The problem I have with this approach is that the name of the PLY file can change, therefore, the name of the generated QML from using balsam will change as well and not sure how to use it in my QML (Basically this hobby project is to create a 3D-visualizer for PLY files, so user can drag and drop any PLY file into the app). I would be happy if you have any thoughts on this.

    Thanks :)

  • Add value text to a QChart's bars

    Solved
    3
    0 Votes
    3 Posts
    116 Views
    R

    Hallo

    I used the code above to add values to the bars, but the x-axis of the label is always the same. see also my code below.
    void ChartWindow::showTeamsBarInOut(){

    QBarSeries *barseries = new QBarSeries(); for(uint8_t teamnr =0; teamnr< aantalTeams;teamnr++){ QBarSet *setTeamInOut = new QBarSet(namen[teamnr]); *setTeamInOut << inn[teamnr] << out[teamnr]; barseries->append(setTeamInOut); } QStringList categories; categories << "In Time" << "Out Time" ; QBarCategoryAxis *axisX = new QBarCategoryAxis(); axisX->append(categories); axisX->setRange(QString("In Time"), QString("Out Time")); QValueAxis *axisY = new QValueAxis(); axisY->setRange(0, maxInOutTime); chart->addAxis(axisY, Qt::AlignLeft); chart->addAxis(axisX, Qt::AlignBottom); chart->addSeries(barseries); barseries->attachAxis(axisY); barseries->attachAxis(axisX); connect(barseries, &QBarSeries::hovered, this, &ChartWindow::toolTip); chartView->setRenderHint(QPainter::Antialiasing); for (int bsets = 0; bsets < barseries->count(); ++bsets) { QBarSet* Bset = barseries->barSets().at(bsets); for (int valSet = 0; valSet < Bset->count(); ++valSet) { QPointF xAs = chart->mapToPosition(QPointF(valSet + 0.5, Bset->at(valSet)), barseries); qreal barX = xAs.x(); QPointF yAs = chart->mapToPosition(QPointF(valSet + 0.5, Bset->at(valSet)), barseries); qreal barY = yAs.y(); qDebug()<<barX<<" "<<barY<< Bset->at(valSet); QGraphicsSimpleTextItem* label = new QGraphicsSimpleTextItem(QString::number(Bset->at(valSet))); label->setPos(barX - label->boundingRect().width() / 2, barY - label->boundingRect().height() - 5); chart->scene()->addItem(label); } }

    }
    and get this image, can someone tell me what i am doing wrong?
    When i hover over the bars i get the wright values

    Naamloos.png

  • 0 Votes
    3 Posts
    86 Views
    S

    First, thanks for the reply.

    When you say that "there's an error signal that you can connect to and from there trigger the reply deletion" you mean that the deleteLater() calls are not well positioned in the code (inside the SLOTS triggered by QNetworkReply::finished)?

    I'm not sure I fully understand the "rate limiter" thing. Can you provide an example on that?

    Regarding the hanging for registered user requests, I now understand why the software fails for them but still works for non-registered users. The rate limit for the latter is 3 requests per second. I've implemented a delay of one second which is fine (I can change it down to 0.333 seconds). For a registered user it's 10 requests per second. The problem is that in the example that I provided (bees) it finds 115 records. The program has to do 6 "NCBI requests" (chunks of 20 records), which actually translate into 12 HTTP requests (it's a two-step process). The 6th one fails due to the rate limit! The thing is that apparently in this case NCBI doesn't return a XML result but something else and that's why the program hangs because it expects to parse a returned XML...

  • QSqlDatabase::tables() get stuck

    Solved
    7
    0 Votes
    7 Posts
    143 Views
    Christian EhrlicherC

    @jsulm said in QSqlDatabase::tables() get stuck:

    At some point Qt will have to change this :-)

    Use the latest version... 🙂
    And no, no difference except support for stuff >2GB

  • SizeToFit a QWidget in a resizeable QGridLayout

    Unsolved
    9
    0 Votes
    9 Posts
    181 Views
    S

    I solved this using the following 2 Steps:

    Calc Size available for the Gradient: void updateGradientPreview() { ... QFontMetrics fm( labelLeft->font()); int width = widget->parentWidget()->width() - fm.boundingRect(labelLeft->text()).width() - fm.boundingRect(labelRight->text()).width() - 10; widget->setFixedWidth(width); int height = 19; QPixmap pixmap(width - 2, height); gradientLabel->setPixmap(pixmap); } Update the pixmap when the parent QDockWidget is resized. Therefore i had to overload the resizeEvent of the parent window void myPalette::resizeEvent(QResizeEvent *event) { QDockWidget::resizeEvent(event); updateGradientPreview() }

    Now the gradient label smoothly aligns when resizing the QDockWidget and it just fills the space available.

  • 0 Votes
    15 Posts
    296 Views
    KenAppleby 0K

    @StudentScripter

    Below is code that I can share. It's a complete example which perhaps does what you need. The void HandlesItem::paint() function is where the graphics transformations are done. It's rather long-winded but it at least shows what's required. It draws a painter path around the model items and deals with scaling and rotation of the model items as well as scaling of the graphics view.

    I'm sorry there is so much code: it's mostly the test framework. It uses mouse wheel events + modifiers to set the scale and rotation of items and the view.

    // main.cpp #include <QGraphicsRectItem> #include <QGraphicsRectItem> #include <QRandomGenerator> #include <QPainter> // A graphics path item that paints a selection graphic rectangle around a model item. class HandlesItem : public QGraphicsPathItem { public: HandlesItem(QGraphicsItem * modelItem, QGraphicsItem * parent =nullptr); void paint(QPainter * painter, const QStyleOptionGraphicsItem * option, QWidget * widget =nullptr) override; void setViewScale(double scale); protected: QGraphicsItem * mModelItem{ nullptr }; }; // A contentless graphics item that acts as a proxy for a model item and manages a HandlesItem for it. // The model item position must be set by setting the Proxy item position. // The model item scale and rotation must be set by the setItemScale() and setItemRotation() functions. // Model items and HandleItems are assumed to transform about their center points. class Proxy : public QGraphicsRectItem { public: Proxy(QGraphicsItem * modelItem, QGraphicsItem * parent =nullptr); void setSelected(bool selected); bool isSelected() const; void setItemRotation(double angle); void setItemScale(double scale); void setViewScale(double scale); // call to set the HandleItem's pen width according to the view scale. protected: QGraphicsItem * mModelItem{ nullptr }; HandlesItem * mHandlesItem{ nullptr }; bool mSelected{ false }; }; // -------------------------------------- HandlesItem::HandlesItem(QGraphicsItem * modelItem, QGraphicsItem * parent) : QGraphicsPathItem{ parent }, mModelItem{ modelItem } { setViewScale(1.0); setTransformOriginPoint(mModelItem->boundingRect().center()); } void HandlesItem::setViewScale(double scale) { QPen pen{ Qt::yellow }; pen.setWidthF(4.0/scale); setPen(pen); } void HandlesItem::paint(QPainter * painter, [[ maybe_unused ]] const QStyleOptionGraphicsItem * option, [[ maybe_unused ]] QWidget * widget) { const double scale{ mModelItem->scale() }; const double margin{ 8.0 / scale }; QRectF r{ mModelItem->boundingRect().adjusted(-margin, -margin, margin, margin) }; const QPointF tl{ r.topLeft() }, tr{ r.topRight() }, br{ r.bottomRight() }, bl{ r.bottomLeft() }; QTransform transform; transform.translate(r.center().x(), r.center().y()); transform.scale(mModelItem->scale(), mModelItem->scale()); transform.rotate(mModelItem->rotation()); transform.translate(-r.center().x(), -r.center().y()); const QPointF tlt{ transform.map(tl) }, trt{ transform.map(tr) }, brt{ transform.map(br) }, blt{ transform.map(bl) }; QPainterPath path; path.moveTo(tlt); path.lineTo(trt); path.lineTo(brt); path.lineTo(blt); path.lineTo(tlt); setPath(path); QGraphicsPathItem::paint(painter, option, widget); } Proxy::Proxy(QGraphicsItem * modelItem, QGraphicsItem * parent) : QGraphicsRectItem{ parent }, mModelItem{ modelItem } { mModelItem->setPos(0, 0); // the model item is positioned by the Proxy. mModelItem->setParentItem(this); setFlag(QGraphicsItem::ItemHasNoContents); mHandlesItem = new HandlesItem{ modelItem, this }; setSelected(false); } void Proxy::setSelected(bool selected) { mSelected = selected; mHandlesItem->setVisible(mSelected); update(); } bool Proxy::isSelected() const { return mSelected; } void Proxy::setItemRotation(double angle) { if (mModelItem) { mModelItem->setTransformOriginPoint(mModelItem->boundingRect().center()); mModelItem->setRotation(mModelItem->rotation() + angle); } } void Proxy::setItemScale(double scale) { if (mModelItem) { mModelItem->setTransformOriginPoint(mModelItem->boundingRect().center()); mModelItem->setScale(mModelItem->scale() * scale); } } void Proxy::setViewScale(double scale) { mHandlesItem->setViewScale(scale); } // The remaining code is a QGraphicsView and QGraphicsScene test framework for the above. #include <QGraphicsView> class GraphicsView : public QGraphicsView { public: GraphicsView(QWidget * parent); void initialise(QGraphicsScene& scene); protected: void mousePressEvent(QMouseEvent * event) override; void mouseMoveEvent(QMouseEvent * event) override; void mouseReleaseEvent(QMouseEvent *) override; void wheelEvent(QWheelEvent *) override; void setSelection(Proxy * item); void initialiseScene(); void setViewTransform(); QTransform makeTransform() const; QList<Proxy *> mItems; Proxy * mSelectedItem{ nullptr }; Proxy * mDragging{ nullptr }; QPointF mMoveScenePoint; double mScale{ 1.0 }; double mRotation{ 0.0 }; }; #include <QMainWindow> #include <QGraphicsScene> #include <QBoxLayout> class HandlesMainWindow : public QMainWindow { public: HandlesMainWindow(QWidget * parent =nullptr); protected: QGraphicsScene mScene; }; HandlesMainWindow::HandlesMainWindow(QWidget * parent) : QMainWindow(parent) { QWidget * centralwidget; QVBoxLayout * verticalLayout; GraphicsView * graphicsView; resize(532, 377); centralwidget = new QWidget(this); centralwidget->setObjectName("centralwidget"); verticalLayout = new QVBoxLayout(centralwidget); verticalLayout->setObjectName("verticalLayout"); graphicsView = new GraphicsView(centralwidget); graphicsView->setObjectName("graphicsView"); verticalLayout->addWidget(graphicsView); setCentralWidget(centralwidget); graphicsView->initialise(mScene); } #include <QMouseEvent> #include <QWheelEvent> namespace { QRandomGenerator& rng() { static QRandomGenerator sRng; return sRng; } QColor randomColor() { return QColor{ rng().bounded(64, 255), rng().bounded(64, 255), rng().bounded(64, 255) }; } QPointF randomPoint() { return QPointF{ 1.0*rng().bounded(20, 400), 1.0*rng().bounded(20, 400) }; } QRectF randomRect() { return QRectF{ 0.0, 0.0, 1.0*rng().bounded(20, 100), 1.0*rng().bounded(20, 100) }; } } GraphicsView::GraphicsView(QWidget * parent) : QGraphicsView{ parent } { setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOff); setRenderHint(QPainter::Antialiasing); setTransformationAnchor(ViewportAnchor::NoAnchor); } void GraphicsView::initialise(QGraphicsScene& scene) { setScene(&scene); initialiseScene(); } void GraphicsView::mousePressEvent(QMouseEvent * event) { const QPoint p{ event->pos() }; QGraphicsItem * item{ itemAt(p) }; if (item) { mDragging = qgraphicsitem_cast<Proxy *>(item->parentItem()); mMoveScenePoint = mapToScene(p); } else { mDragging = nullptr; } } void GraphicsView::mouseMoveEvent(QMouseEvent * event) { const QPoint p{ event->pos() }; if (mDragging) { const QPointF sp{ mapToScene(p) }; mDragging->moveBy(sp.x() - mMoveScenePoint.x(), sp.y() - mMoveScenePoint.y()); mMoveScenePoint = sp; } } void GraphicsView::mouseReleaseEvent(QMouseEvent * event) { mDragging = nullptr; const QPoint p{ event->pos() }; QGraphicsItem * item{ itemAt(p) }; if (item) { setSelection(qgraphicsitem_cast<Proxy *>(item->parentItem())); } else { setSelection(nullptr); } } void GraphicsView::wheelEvent(QWheelEvent * event) { if (event->modifiers() == Qt::NoModifier) { double deltaScale{ 1.0 }; QPoint p = event->angleDelta(); if (p.y() > 0) { deltaScale = 1.1; } else if (p.y() < 0) { deltaScale = 1.0/1.1; } event->accept(); if (mSelectedItem) { mSelectedItem->setItemScale(deltaScale); } else { mScale = mScale * deltaScale; setViewTransform(); } } else if (event->modifiers() == Qt::ControlModifier){ QPoint p = event->angleDelta(); double rotation{ 0.0 }; if (p.y() > 0) { rotation = 2.0; } else if (p.y() < 0) { rotation = -2.0; } event->accept(); if (mSelectedItem) { mSelectedItem->setItemRotation(rotation); } else { mRotation += rotation; setViewTransform(); } } } void GraphicsView::setSelection(Proxy * item) { mSelectedItem = item; if (item) { item->setSelected(true); } for (auto i : mItems) { if (not (i == item)) { i->setSelected(false); } } } void GraphicsView::setViewTransform() { setTransform(makeTransform()); for (auto i : mItems) { i->setViewScale(mScale); } } QTransform GraphicsView::makeTransform() const { QTransform result; const QPointF center{ rect().center() }; result.translate(center.x(), center.y()); result.scale(mScale, mScale); result.rotate(mRotation); result.translate(-center.x(), -center.y()); return result; } void GraphicsView::initialiseScene() { scene()->setBackgroundBrush(QBrush{ Qt::cyan }); for (int i = 0; i < 20; i++) { QGraphicsRectItem * item{ new QGraphicsRectItem(::randomRect()) }; item->setBrush(QBrush{ ::randomColor() }); Proxy * proxy{ new Proxy{ item } }; proxy->setPos(::randomPoint()); scene()->addItem(proxy); mItems << proxy; } } #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); HandlesMainWindow w; w.show(); return a.exec(); }
  • Orderless completion in QCompleter

    Unsolved
    4
    0 Votes
    4 Posts
    61 Views
    Pl45m4P

    @dheerajshenoy said in Orderless completion in QCompleter:

    I start typing the word and press space, the completion popup hides and is not shown.

    I think this is because the completer treats it as new match/word then.
    Can't tell how to change this (or how to match a result that contains multiple, by whitespace separated, words)

    Maybe looking into the file path handling helps:
    The input is separated by slash or backslash and split into the single layers of the tree

    https://doc.qt.io/qt-6/qcompleter.html#handling-tree-models
  • 0 Votes
    5 Posts
    93 Views
    D

    @jsulm The version is Qt Creator 14.0.2 (Community).
    Immagine 2024-11-12 113551.png
    I have these settings

  • 0 Votes
    3 Posts
    66 Views
    M

    @Bonnie Thank you for pointing me in the right direction. I turns out the issue wasn't height, or min-height, but rather an inherited padding, that just happened to make it look like it was expanding to the full height of the QHBoxLayout.