Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.4k Topics 456.4k Posts
  • 0 Votes
    4 Posts
    180 Views
    jsulmJ
    @Vishal-Panchal You can check on https://bugreports.qt.io/issues/ whether this is a known issue and if not file a bug providing a minimal reproducible example of the issue.
  • Updating test step logs only without updating test case steps

    Unsolved qtest api
    2
    0 Votes
    2 Posts
    804 Views
    C
    @kamal07 Do you have a question?
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    2 Views
    No one has replied
  • 0 Votes
    2 Posts
    233 Views
    C
    @deshanharshana Two options: Build the your source code on a Windows machine (virtual or physical) with pre-built Qt libraries and tools. Install MingW64 on Ubuntu to get a tool chain targeting Windows, cross-compile Qt from source to get a set of libraries for Windows, cross-compile your source code with the MingW tool chain and Qt libraries. You can try something like MXE to shortcut this process The first option is generally far easier.
  • QML Mapbox "The geoservices provider is not supported"

    Unsolved
    3
    0 Votes
    3 Posts
    988 Views
    JKSHJ
    Qt 6 will not support the Mapbox backend. See the section "Reducing the number of included backends" at https://www.qt.io/blog/the-road-to-qt-location
  • How to align QComboBox text

    Unsolved
    2
    0 Votes
    2 Posts
    339 Views
    SGaistS
    Hi, You seem to install your class as a filter for its various components. What are you doing in the filter ?
  • wiki problem

    Unsolved
    4
    0 Votes
    4 Posts
    246 Views
    SGaistS
    So it's not the wiki but the documentation. It states that: Indicates that the widget should have a translucent background, i.e., any non-opaque regions of the widgets will be translucent because the widget will have an alpha channel. Nowhere is it said that it will make the widget transparent. Just that the alpha channel will be taken into account.
  • QPushButton::text() returning another button's text

    Solved
    9
    0 Votes
    9 Posts
    470 Views
    Pl45m4P
    @clarify Show the code, provide an example for others to reproduce it, or it doesnt happened :) If it would be like you said, millions of Qt users and devs would face the same behavior. Like @JonB and @Christian-Ehrlicher said, I doubt that it is a bug in Qt ifself and not something wrong with your code
  • proper use of CMAKE_SOURCE_DIR

    Solved
    5
    0 Votes
    5 Posts
    554 Views
    mzimmersM
    @Christian-Ehrlicher said in proper use of CMAKE_SOURCE_DIR: I personally install qm files either in an 'translations' subdir or directly embed them in the resource file. Oh, I guess I misunderstood that line -- I thought he was referring to the build directory. But your answer implies that the install is actually within the source directory. I think I'd like to use the first approach you mentioned. Should I create a variable for this directory within Creator, or is there something predefined for this purpose? Thanks...
  • How do I do infinite wait for serial?

    Unsolved
    9
    0 Votes
    9 Posts
    619 Views
    jsulmJ
    @BAKI said in How do I do infinite wait for serial?: This is the code I ran You should really take a closer look at this line of code...
  • Noticable slowdown when using

    Unsolved opengl openglwidget dockwidget openglwindow
    2
    0 Votes
    2 Posts
    539 Views
    S
    @wookie Oh man, getting Qt to work properly in a graphics intensive application at a good frame rate is tricky! QOpenGLWidget has absolute dog shit performance. Unfortunately you need it if you want the best integration with the rest of the Qt and nice things such as context menus. In my tests though rendering with QOpenGLWidget has an order of magnitude worse performance than simply using a QGLWidget or just QWindow. I think something really stupid is happening inside the implementations.. (texture copy or something like that perhaps..) In general one problem is that if your setSwapInterval actually works (plenty of bugs there across the whole stack) you're blocking your thread until your swap returns. So if your display is running at 60fps then you're stuck there for 16ms at a time which delays any user input processing that much since the event loop can't run. But it gets even worse if you're rendering multiple windows/widgets! If you're swapping twice then you're blocking twice and now your frame rate is halved, so you're dropping to 30fps and the UI is sluggish as a snail! In my game editor I've got a decent enough solution but it has taken some effort. Essentially what I've done is: I've settled on QWindow myself and creating the context myself and then wrapping that up inside QWidgetContainer. I use a "busy loop" that runs and uses QApplication::processEvents directly with AllEvents | WaitMoreEvents I use a separate thread to give a heartbeat, it sleeps some user defined interval and then posts a message to the main thread (on windows it'll try to use the compositor flush to sleep). Main thread then renders on the heartbeat message. I disabled app level VSYNC completely (i.e setSwapInterval is always 0) The key takeaways are that if you use any kind of blocking such as VSYNC or thread sleep etc. in your main thread your UI janks! if you don't use any kind of blocking and just busy loop as fast you can in your event loop you burn a lot of cycles and drain the users battery! so whatever solution you want to create you need ideally scaling so the frame rate is good and scales to the load interruptible waits for throttling the main loop, react to user input as soon as possible steady fps with good timing resolution
  • This topic is deleted!

    Unsolved
    1
    0 Votes
    1 Posts
    11 Views
    No one has replied
  • QProcess changes command behavior

    Unsolved
    3
    0 Votes
    3 Posts
    224 Views
    S
    @Christian-Ehrlicher is right. We need to see your code. Most of the time there is misunderstandings in how to provide command line parameters to QProcess.
  • QThread - good practice implementation

    Unsolved
    6
    1 Votes
    6 Posts
    1k Views
    S
    @SamiV123 said in QThread - good practice implementation: Then you can create a separate thread, or a thread pool And in the case of a thread pool think about using QtConcurrent. If QtConcurrent::run() works for you, don't bother figuring out QThread.
  • QChartView Y axis alignment

    Unsolved
    1
    0 Votes
    1 Posts
    157 Views
    No one has replied
  • Must construct a QApplication before a QWidget

    Unsolved
    6
    0 Votes
    6 Posts
    11k Views
    JonBJ
    @jeremy_k said in Must construct a QApplication before a QWidget: We can't tell without the indentation. The code could be: Ah, yes, exactly! Which is why I asked the OP to use code tags especially for Python for just this reason :)
  • [SOLVED] QApplication::beep() - no sound on linux

    15
    0 Votes
    15 Posts
    20k Views
    JonBJ
    @tsvigo It seems a shame to run an external process, and have to install a program, each time you want to make a beep sound....
  • Record system audio using Qt 6

    Unsolved audio recording audio
    1
    0 Votes
    1 Posts
    256 Views
    No one has replied
  • Qt Location plugins and excluding road types

    Unsolved
    1
    0 Votes
    1 Posts
    116 Views
    No one has replied
  • Interactive elements in delegate

    Solved
    6
    0 Votes
    6 Posts
    680 Views
    ABDUA
    @SGaist Thanks! I've done the behavior I need without using editors. I'll leave the code here. In the future, it may be useful to someone: class Document : public QTextDocument { Q_OBJECT public: explicit Document(QObject *parent = nullptr) : QTextDocument{parent} , textCursor_{this} { setDocumentMargin(0); } int selectionStartPos() const { return textCursor_.selectionStart(); } int selectionEndPos() const { return textCursor_.selectionEnd(); } void setCursorPosition(int pos, QTextCursor::MoveMode mode = QTextCursor::MoveAnchor) { clearSelection(); textCursor_.setPosition(pos, mode); highlightSelection(); } bool moveCursorPosition(QTextCursor::MoveOperation op, QTextCursor::MoveMode mm= QTextCursor::MoveAnchor, int n = 1) { clearSelection(); const bool result = textCursor_.movePosition(op, mm, n); highlightSelection(); return result; } void select(QTextCursor::SelectionType selection) { clearSelection(); textCursor_.select(selection); selectedWordOnDoubleClick_ = textCursor_; highlightSelection(); } void extendWordwiseSelection(int newPos) { QTextCursor selected = textCursor_; QTextCursor tempCursor = textCursor_; tempCursor.setPosition(newPos, QTextCursor::KeepAnchor); if (!tempCursor.movePosition(QTextCursor::StartOfWord)) return; const int wordStartPos = tempCursor.position(); if (!tempCursor.movePosition(QTextCursor::EndOfWord)) return; const int wordEndPos = tempCursor.position(); if (newPos < selectedWordOnDoubleClick_.position()) { setCursorPosition(selected.selectionEnd()); setCursorPosition(wordStartPos, QTextCursor::KeepAnchor); } else { setCursorPosition(selected.selectionStart()); setCursorPosition(wordEndPos, QTextCursor::KeepAnchor); } } QString selectedText() const { return textCursor_.selectedText(); } private: void clearSelection() { QTextCharFormat defaultFormat; textCursor_.setCharFormat(defaultFormat); } void highlightSelection() { QTextCharFormat selectFormat = textCursor_.charFormat(); selectFormat.setBackground(QApplication::palette().highlight().color()); selectFormat.setForeground(QApplication::palette().highlightedText().color()); textCursor_.setCharFormat(selectFormat); } private: QTextCursor textCursor_; QTextCursor selectedWordOnDoubleClick_; }; class Delegate : public QStyledItemDelegate { public: Delegate(QObject *parent = nullptr) : QStyledItemDelegate{parent} { } void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override { painter->save(); painter->fillRect(option.rect, Qt::red); if (index == interactiveIndex_) { painter->translate(option.rect.topLeft()); doc_->documentLayout()->draw(painter, QAbstractTextDocumentLayout::PaintContext()); } else { const auto text = index.data(Model::MyText).toString(); painter->drawText(option.rect, text); } painter->restore(); } QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override { return QSize{option.rect.width(), 40}; } QModelIndex interactiveIndex() const { return interactiveIndex_; } void setInteractiveIndex(const QModelIndex &newInteractiveIndex) { interactiveIndex_ = newInteractiveIndex; } QSharedPointer<Document> doc() const { return doc_; } void setDoc(QSharedPointer<Document> newDoc) { doc_ = newDoc; } private: QModelIndex interactiveIndex_; QSharedPointer<Document> doc_; }; class Model : public QAbstractListModel { public: enum Roles { MyText = Qt::UserRole + 1 }; Model(QObject *parent = nullptr) : QAbstractListModel{parent} { texts_.append("One One One\n" "One One One"); texts_.append("Two Two Two\n" "Two Two Two"); texts_.append("Three Three Three\n" "Three Three Three"); texts_.append("Four Four Four\n" "Four Four Four"); } int rowCount(const QModelIndex &parent) const override { return texts_.size(); } QVariant data(const QModelIndex &index, int role) const override { if (role == Roles::MyText) return texts_[index.row()]; return QVariant{}; } Qt::ItemFlags flags(const QModelIndex &index) const override { return QAbstractItemModel::flags(index); } private: QStringList texts_; }; class View : public QListView { public: View(QWidget *parent = nullptr) : QListView{parent} , model_{new Model{this}} , delegate_{new Delegate{this}} { setModel(model_); setItemDelegate(delegate_); setMouseTracking(true); } protected: void mousePressEvent(QMouseEvent *event) override { pressedPos_ = event->pos(); previousPressedIndex_ = pressedIndex_; pressedIndex_ = indexAt(pressedPos_); if (pressedIndex_ != previousPressedIndex_) { // Repaint previous pressed as static text. Means no selection draws update(previousPressedIndex_); } const QString text = pressedIndex_.data(Model::MyText).toString(); QSharedPointer<Document> doc{new Document}; doc->setPlainText(text); const int startPos = getRelativeCursorPos(doc, pressedIndex_, pressedPos_); doc->setCursorPosition(startPos); delegate_->setInteractiveIndex(pressedIndex_); delegate_->setDoc(doc); wordSelection_ = false; QListView::mousePressEvent(event); } void mouseMoveEvent(QMouseEvent *event) override { const QPoint currentMousePos = event->pos(); if (indexAt(currentMousePos).isValid()) { if ((!QApplication::overrideCursor() || QApplication::overrideCursor()->shape() != Qt::IBeamCursor)) { QApplication::setOverrideCursor(Qt::IBeamCursor); } } else { QApplication::restoreOverrideCursor(); } if (event->buttons() & Qt::LeftButton) { const QPoint currentMousePos = event->pos(); QSharedPointer<Document> doc = delegate_->doc(); const int endPos = getRelativeCursorPos(doc, pressedIndex_, currentMousePos); if (wordSelection_) { doc->extendWordwiseSelection(endPos); } else { doc->setCursorPosition(endPos, QTextCursor::KeepAnchor); } update(pressedIndex_); } QListView::mouseMoveEvent(event); } void mouseDoubleClickEvent(QMouseEvent *event) override { QSharedPointer<Document> doc = delegate_->doc(); doc->select(QTextCursor::WordUnderCursor); update(pressedIndex_); wordSelection_ = true; QListView::mouseDoubleClickEvent(event); } void mouseReleaseEvent(QMouseEvent *event) override { QListView::mouseReleaseEvent(event); QSharedPointer<Document> doc = delegate_->doc(); QApplication::clipboard()->setText(doc->selectedText()); } private: int getRelativeCursorPos(const QSharedPointer<Document> &doc, const QModelIndex &index, const QPoint &mousePos) const { const QRect itemRect = visualRect(index); const QPoint relativePos = mousePos - itemRect.topLeft(); return doc->documentLayout()->hitTest(relativePos, Qt::FuzzyHit); } private: Model *model_ = nullptr; Delegate *delegate_ = nullptr; QModelIndex previousPressedIndex_; QModelIndex pressedIndex_; QPoint pressedPos_; bool wordSelection_ = false; }; Perhaps the code is too big to ask if it can be improved somewhere. I did everything I could. But still I will leave the post unresolved for a short time. Maybe there will be people who will advise me to improve my code. I am open and grateful to anyone who can help improve the implementation in any way.