Skip to content

General and Desktop

This is where all the desktop OS and general Qt questions belong.
83.5k Topics 457.3k Posts
  • qt install problem

    Unsolved
    2
    0 Votes
    2 Posts
    125 Views
    sierdzioS
    @starlight make sure QT_DEBUG_PLUGINS is not defined.
  • axis setRange causes read acces violation

    Solved
    3
    0 Votes
    3 Posts
    250 Views
    W
    @Christian-Ehrlicher Exactly. You are right! Thank you for your help!
  • How to get git-commit ID during build and display it as version information

    Solved
    8
    0 Votes
    8 Posts
    3k Views
    Y
    @KH-219Design @JoeCFD @SGaist Thank you for nice solutions! I tried @JoeCFD 's solution. It worked and suitable for me!
  • Additional info upon compiling with Qt Creator

    Unsolved
    5
    0 Votes
    5 Posts
    394 Views
    C
    @JacobNovitsky said in Additional info upon compiling with Qt Creator: how to interpret below? file Static_lib.h Static_lib.h: C++ source, ASCII text The file command is inspecting the Static_lib.h file and, using its rules, determining that the file contains C++ source or ASCII text. This is indeed the case. This file is not the precompiled output file generated by the compilation at step 1. in my example. how to include -H to my building command, if I build program with Qt Creator? I would not bother. Run it a one file compile once manually, verify the result, and then forget about it. I you really must have this extra output in every compilation then add it to the project file's CFLAGS, something like this linux-g++: QMAKE_CFLAGS_DEBUG += -H
  • How assign the enter key to a button

    20
    0 Votes
    20 Posts
    30k Views
    C
    @fs_tigre great!!
  • QMap -> what does .contains() compare?

    Unsolved
    4
    0 Votes
    4 Posts
    636 Views
    Flaming MoeF
    Okay I was not aware, that == is the compare operator since others are also overloaded bool operator<=(QTime lhs, QTime rhs) bool operator==(QTime lhs, QTime rhs) bool operator>(QTime lhs, QTime rhs) bool operator>=(QTime lhs, QTime rhs)
  • Application is getting closed while emitting signal in QML file

    Unsolved
    1
    0 Votes
    1 Posts
    107 Views
    No one has replied
  • QTreeView prevent stacking indentation after certain childs.

    Unsolved
    8
    0 Votes
    8 Posts
    690 Views
    S
    @JonB oh sorry my oversight, here is the code of my delegate: delegate.cpp: #include "ViewLayerItemDelegate.h" #include <QStyledItemDelegate> #include <QPainter> #include <QApplication> #include <QItemSelectionModel> #include <QMouseEvent> #include "ViewLayerList.h" #include <QTimer> ViewLayerItemDelegate::ViewLayerItemDelegate(QObject *parent) : QStyledItemDelegate{parent} { } QWidget *ViewLayerItemDelegate::createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const { qDebug() << "Editor created"; LineEditCheckBoxWidget *editor = new LineEditCheckBoxWidget(parent); // Verbinden Sie das textChanged() Signal des LineEdits mit Ihrem Slot connect(editor->lineEdit, &QLineEdit::textChanged, this, &ViewLayerItemDelegate::onLineEditTextChanged); //Ein Timer um direkt die Editierung des LineEdit zu ermöglichen QTimer::singleShot(0, editor->lineEdit, SLOT(setFocus())); return editor; } void ViewLayerItemDelegate::setEditorData(QWidget *editor, const QModelIndex &index) const { LineEditCheckBoxWidget *widget = static_cast<LineEditCheckBoxWidget *>(editor); // Setzen Sie die Werte der SpinBox und CheckBox basierend auf den Modellwerten QString lineEditvalue = index.model()->data(index, Qt::EditRole).toString(); bool checkBoxValue = index.model()->data(index, Qt::CheckStateRole).toBool(); widget->lineEdit->setText(lineEditvalue); widget->checkBox->setChecked(checkBoxValue); widget->setFocus(); widget->lineEdit->setFocus(Qt::MouseFocusReason); // Editor aktivieren widget->lineEdit->setStyleSheet("background: white"); widget->iconLabel->setAttribute(Qt::WA_TranslucentBackground); //widget->setStyleSheet("background: white"); // Setzen Sie den bearbeiteten Index const_cast<ViewLayerItemDelegate*>(this)->setCurrentlyEditedIndex(index); } void ViewLayerItemDelegate::setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const { LineEditCheckBoxWidget *widget = static_cast<LineEditCheckBoxWidget *>(editor); // Speichern Sie die Werte der SpinBox und CheckBox im Modell QString lineEditvalue = widget->lineEdit->text(); bool checkBoxValue = widget->checkBox->isChecked(); model->setData(index, lineEditvalue, Qt::EditRole); model->setData(index, checkBoxValue ? Qt::Checked : Qt::Unchecked, Qt::CheckStateRole); qDebug() << "Model data set"; // Setzen Sie den bearbeiteten Index zurück const_cast<ViewLayerItemDelegate*>(this)->setCurrentlyEditedIndex(QModelIndex()); } void ViewLayerItemDelegate::updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const { editor->setGeometry(option.rect); } QSize ViewLayerItemDelegate::sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const { QSize size = QStyledItemDelegate::sizeHint(option, index); size.setHeight(40); // Setzen Sie hier die gewünschte Höhe // Ändern Sie die Einrückung basierend auf dem Level des Items (z.B., hier um 20 Pixel). int indentationLevel = index.column(); // Hier als Beispiel die Einrückung basierend auf der Spalte. size.rwidth() -= indentationLevel * 40; // Die Einrückung um 20 Pixel erhöhen. return size; } void ViewLayerItemDelegate::paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const { QStyleOptionViewItem opt = option; initStyleOption(&opt, index); // Überprüfen Sie, ob der aktuelle Index bearbeitet wird if (index == currentlyEditedIndex) { return; } // Setzen Sie die Werte der SpinBox und CheckBox basierend auf den Modellwerten QString lineEditvalue = index.model()->data(index, Qt::EditRole).toString(); bool checkBoxValue = index.model()->data(index, Qt::CheckStateRole).toBool(); // Laden Sie das Icon und skalieren Sie es QPixmap iconPixmap("://resource/quick.png"); // Ersetzen Sie dies durch den Pfad zu Ihrer Icon-Datei QPixmap scaledPixmap = iconPixmap.scaled(32, 32, Qt::KeepAspectRatio, Qt::SmoothTransformation); // Berechnen Sie die Position für das Icon int centerY = option.rect.top() + option.rect.height() / 2; int iconY = centerY - scaledPixmap.height() / 2; QPoint iconPos = QPoint(option.rect.left() + 10, iconY); // Zeichnen Sie das Pixmap mit dem QPainter painter->drawPixmap(iconPos, scaledPixmap); // Berechnen Sie die Position und Größe für das LineEdit QRect lineEditRect = option.rect; lineEditRect.setLeft(iconPos.x() + scaledPixmap.width() + 10); // Adjust as needed lineEditRect.setRight(option.rect.right() - 10-35); // Adjust as needed // Erstellen Sie ein QStyleOptionFrame für das LineEdit QStyleOptionFrame lineEditOption; lineEditOption.lineWidth = 1; // Setzen Sie die Liniendicke auf 1 lineEditOption.rect = lineEditRect; // Zeichnen Sie das LineEdit QApplication::style()->drawControl(QStyle::CE_ShapedFrame, &lineEditOption, painter); // Überprüfen Sie, ob der Text leer ist und zeichnen Sie den Platzhaltertext // Zeichnen Sie den Text des LineEdits, considering truncation // Überprüfen Sie, ob der Text leer ist und zeichnen Sie den Platzhaltertext if (lineEditvalue.isEmpty()) { painter->drawText(lineEditOption.rect.adjusted(2, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, "<Empty>"); } else { // Hier wird die maximale Breite des Texts festgelegt, bevor er abgeschnitten wird int maxTextWidth = lineEditRect.width(); // Berechnen Sie die Größe des Texts QFontMetrics fm(painter->font()); QString displayedText = fm.elidedText(lineEditvalue, Qt::ElideRight, maxTextWidth - 10); painter->drawText(lineEditOption.rect.adjusted(2, 0, 0, 0), Qt::AlignLeft | Qt::AlignVCenter, displayedText); } // Berechnen Sie die Position und Größe für die CheckBox QRect checkBoxRect = option.rect; checkBoxRect.setLeft(lineEditRect.right() +35- 22); // Adjust as needed checkBoxRect.setRight(option.rect.right() - 10); // Adjust as needed // Erstellen Sie ein QStyleOptionButton für die CheckBox QStyleOptionButton checkBoxOption; checkBoxOption.state = checkBoxValue ? QStyle::State_On : QStyle::State_Off; checkBoxOption.rect = checkBoxRect; /* //CODE NUR ZUM VISUELLEN DEBUGGEN DER BEREICHE: // Zeichnen Sie ein rotes Rechteck um das LineEdit QPen redPen(Qt::red); painter->setPen(redPen); painter->drawRect(lineEditRect); // Zeichnen Sie ein rotes Rechteck um das LineEdit QPen bluePen(Qt::blue); painter->setPen(bluePen); painter->drawRect(checkBoxRect); */ // Zeichnen Sie die CheckBox QApplication::style()->drawControl(QStyle::CE_CheckBox, &checkBoxOption, painter); } bool ViewLayerItemDelegate::editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) { if(event->type() == QEvent::MouseButtonPress) { QMouseEvent *mouseEvent = static_cast<QMouseEvent*>(event); if (const QTreeView* view = qobject_cast<const QTreeView*>(option.widget)) { const QRect itemRect = view->visualRect(index); ClickPosition = mouseEvent->position() - itemRect.topLeft(); // press position in item's coords //QRect itemRect = option.rect; qDebug() << "Click position: " << ClickPosition; qDebug() << "Item Rect: " <<itemRect; if(ClickPosition.x() >= itemRect.width()-35 && ClickPosition.x() <= itemRect.width()-20) { // Invert the state of the checkbox bool value = index.data(Qt::CheckStateRole).toBool(); model->setData(index, !value, Qt::CheckStateRole); } } } // Standardverhalten beibehalten für andere Ereignisse return QStyledItemDelegate::editorEvent(event, model, option, index); } // Slot-Implementierung void ViewLayerItemDelegate::onLineEditTextChanged(const QString &text) { // Hier können Sie die gewünschte Aktion ausführen, wenn der Text im LineEdit bearbeitet wird qDebug() << "LineEdit text changed to:" << text; } void LineEditCheckBoxWidget::mousePressEvent(QMouseEvent *event) { qDebug() << "Test clicked"; this->lineEdit->setStyleSheet("background: transparent;"); QWidget::mousePressEvent(event); } void ViewLayerItemDelegate::setCurrentlyEditedIndex(const QModelIndex &index) { currentlyEditedIndex = index; } delegate.h: #ifndef VIEWLAYERITEMDELEGATE_H #define VIEWLAYERITEMDELEGATE_H #include <QStyledItemDelegate> #include <QModelIndex> #include <QObject> #include <QSize> #include <QLineEdit> #include <QStandardItemModel> #include <QCheckBox> #include <QFormLayout> #include <QLabel> #include <QPushButton> // Definieren Sie das benutzerdefinierte Widget class LineEditCheckBoxWidget : public QWidget { Q_OBJECT public: QLineEdit *lineEdit; QCheckBox *checkBox; QLabel *iconLabel; LineEditCheckBoxWidget(QWidget *parent = nullptr) : QWidget(parent) { QHBoxLayout *layout = new QHBoxLayout(this); layout->setContentsMargins(10,0,20,0); layout->setSpacing(0); lineEdit = new QLineEdit(this); checkBox = new QCheckBox(this); iconLabel = new QLabel(this); // Laden Sie das Icon und setzen Sie es auf das QLabel QPixmap iconPixmap("://resource/quick.png"); // Ersetzen Sie dies durch den Pfad zu Ihrer Icon-Datei QPixmap scaledPixmap = iconPixmap.scaled(32, 32, Qt::KeepAspectRatio, Qt::SmoothTransformation); iconLabel->setPixmap(scaledPixmap); this->setStyleSheet("background-color: transparent"); layout->addWidget(iconLabel); layout->addSpacing(10); layout->addWidget(lineEdit); layout->addSpacing(10); layout->addWidget(checkBox); // Zugriff auf das QLineEdit-Widget und setzen Sie den Hintergrund transparent lineEdit->setStyleSheet("background-color: transparent;"); lineEdit->setFrame(false); lineEdit->setPlaceholderText("<Empty>"); checkBox->setStyleSheet("background-color: transparent"); //QPoint globalPos = checkBox->mapToGlobal(QPoint(0, 0)); //qDebug() << "Global position of checkbox on init: " << globalPos; } // QWidget interface protected: void mousePressEvent(QMouseEvent *event) override; signals: }; class ViewLayerItemDelegate : public QStyledItemDelegate { Q_OBJECT public: explicit ViewLayerItemDelegate(QObject *parent = nullptr); QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const override; void setEditorData(QWidget *editor, const QModelIndex &index) const override; void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const override; void updateEditorGeometry(QWidget *editor, const QStyleOptionViewItem &option, const QModelIndex &index) const override; QSize sizeHint(const QStyleOptionViewItem &option, const QModelIndex &index) const override; void paint(QPainter *painter, const QStyleOptionViewItem &option, const QModelIndex &index) const override; bool editorEvent(QEvent *event, QAbstractItemModel *model, const QStyleOptionViewItem &option, const QModelIndex &index) override; QModelIndex currentlyEditedIndex; void setCurrentlyEditedIndex(const QModelIndex &index); //Speichert die Position wo geklickt wurde QPointF ClickPosition; public slots: void onLineEditTextChanged(const QString &text); signals: }; #endif // VIEWLAYERITEMDELEGATE_H
  • QTreeView can span children's items to a new item

    Unsolved
    7
    0 Votes
    7 Posts
    665 Views
    J
    @SGaist I read the qt example "Qt\Examples\Qt-6.5.1\widgets\itemviews\stardelegate". It uses StarDelegate which subclass QStyledItemDelegate, but the staritem size is controled by header. How a custom QStyledItemDelegate can expanding the item size that dones't control by header?
  • warn_unused_result | warning: ignoring return value of ‘int system(const char*)’

    Unsolved
    12
    0 Votes
    12 Posts
    3k Views
    JonBJ
    @JacobNovitsky said in warn_unused_result | warning: ignoring return value of ‘int system(const char*)’: @JonB because I see result and dont need in the context numeric result to be returned Of course you do need to look at the result. If it is non-0 you need to investigate and possibly report to user/outside world. For example, if it returns -1 that means creating the new process for the command to be executed fails. How can you not need to notice that? It is a recipe for having potentially bad behaviour at user runtime yet not indicating anything about it and then neither you nor user knows something has gone wrong. That is precisely why someone has bothered to mark the function warn_unused_result. If nothing else maybe do something like qDebug() the result when non-0. Rather than setting a compiler option to suppress warnings on any/all functions with warn_unused_result just for the sake of one system() call somewhere.
  • How to get speed network interface

    Unsolved
    5
    0 Votes
    5 Posts
    586 Views
    Christian EhrlicherC
    @fa_2 said in How to get speed network interface: Does anyone have a solution ? No, Qt has no option for this. You have to go low-level by yourself.
  • Do I need to include Q headers inner Q headers and to make these pre-compiled

    Locked Unsolved
    5
    0 Votes
    5 Posts
    335 Views
    Christian EhrlicherC
    Dupe of https://forum.qt.io/topic/150964/how-to-set-needed-permission-so-i-can-edit-qt-headers-from-qt-creator Please stop spamming the forum with the same question...
  • How to use precompiled headers (pch) for C++ with Qt

    Locked Unsolved
    9
    0 Votes
    9 Posts
    1k Views
    Christian EhrlicherC
    Dupe of https://forum.qt.io/topic/150964/how-to-set-needed-permission-so-i-can-edit-qt-headers-from-qt-creator/6
  • pre-compile Qt headers

    Locked Unsolved
    2
    0 Votes
    2 Posts
    145 Views
    Christian EhrlicherC
    Dupe of https://forum.qt.io/topic/150964/how-to-set-needed-permission-so-i-can-edit-qt-headers-from-qt-creator
  • How to set needed permission so I can edit qt headers from qt creator?

    Unsolved
    6
    0 Votes
    6 Posts
    530 Views
    C
    @JacobNovitsky Just follow the example in the documentation Project file. Only 2 lines added QT += core gui greaterThan(QT_MAJOR_VERSION, 4): QT += widgets CONFIG += c++17 # You can make your code fail to compile if it uses deprecated APIs. # In order to do so, uncomment the following line. #DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0x060000 # disables all the APIs deprecated before Qt 6.0.0 CONFIG += precompile_header PRECOMPILED_HEADER = precompiled.h SOURCES += \ main.cpp \ widget.cpp HEADERS += \ widget.h # Default rules for deployment. qnx: target.path = /tmp/$${TARGET}/bin else: unix:!android: target.path = /opt/$${TARGET}/bin !isEmpty(target.path): INSTALLS += target Headers to be precompiled (precompiled.h): // Add C includes here // none in this example #if defined __cplusplus // Add stable C++ includes here #include <QApplication> #include <QPushButton> #include <QLabel> #include <QLineEdit> #endif And the unmodified code of the program: #ifndef WIDGET_H #define WIDGET_H #include <QWidget> class Widget : public QWidget { Q_OBJECT public: Widget(QWidget *parent = nullptr); ~Widget(); }; #endif // WIDGET_H #include "widget.h" #include <QLabel> #include <QPushButton> #include <QLineEdit> #include <QVBoxLayout> Widget::Widget(QWidget *parent) : QWidget(parent) { QVBoxLayout *layout = new QVBoxLayout(this); QLabel *label = new QLabel("Hello, world!"); QPushButton *button = new QPushButton("Hello, button!"); QLineEdit *edit = new QLineEdit("Hello, editor!"); layout->addWidget(label); layout->addWidget(button); layout->addWidget(edit); } Widget::~Widget() { } #include "widget.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Widget w; w.show(); return a.exec(); } Re-run qmake, build, and precompiling/using the headers will happen. Any header not in the precompiled set will be handled normally.
  • Changing a QCalenderWidgets icons.

    Solved qcalenderwidget qprivatewidget
    8
    0 Votes
    8 Posts
    4k Views
    R
    this is what worked for me class CalendarWidget(QtWidgets.QCalendarWidget): def __init__(self, parent=None): super(CalendarWidget, self).__init__(parent, verticalHeaderFormat=QtWidgets.QCalendarWidget.NoVerticalHeader, gridVisible=False) self.setObjectName("patient_visit_date_calendar_widget") prev_button = self.findChild(QtWidgets.QToolButton, "qt_calendar_prevmonth") next_button = self.findChild(QtWidgets.QToolButton, "qt_calendar_nextmonth") # Create QIcon instances for your icons prev_icon = QIcon(":resources/icons/arrow_back.svg") next_icon = QIcon(":resources/icons/arrow_forward.svg") # Set the icons to the buttons prev_button.setIcon(prev_icon) next_button.setIcon(next_icon) for btn in (prev_button, next_button): btn.setIconSize(QtCore.QSize(15, 15)) for d in (QtCore.Qt.Saturday, QtCore.Qt.Sunday,): fmt = self.weekdayTextFormat(d) fmt.setForeground(QtCore.Qt.darkGray) self.setWeekdayTextFormat(d, fmt) self.setStyleSheet(QSS) def paintCell(self, painter, rect, date): if date == self.selectedDate(): painter.save() painter.fillRect(rect, QtGui.QColor("white")) painter.setPen(QtCore.Qt.NoPen) painter.setBrush(QtGui.QColor(10, 186, 181, 100)) r = QtCore.QRect(QtCore.QPoint(), min(rect.width(), rect.height())*QtCore.QSize(1, 1)) r.moveCenter(rect.center()) painter.drawEllipse(r) painter.setPen(QtGui.QPen(QtGui.QColor("white"))) painter.drawText(rect, QtCore.Qt.AlignCenter, str(date.day())) painter.restore() else: super(CalendarWidget, self).paintCell(painter, rect, date)
  • Qt Project freezes at start and does not show window

    Unsolved
    5
    0 Votes
    5 Posts
    544 Views
    SGaistS
    Did you already start your application with the QT_DEBUG_PLUGINS environment set to one ?
  • QMediaPlayer Problems with H265 and H264 Streams.

    Unsolved
    2
    0 Votes
    2 Posts
    2k Views
    SGaistS
    Hi and welcome to devnet, It seems you are missing the libva package on your system. Also, which version of OpenSSL do you have installed ?
  • 0 Votes
    4 Posts
    514 Views
    SGaistS
    Creating a base widget that does that handling is the correct way. However you can't optimize more. Each of your widgets will have custom texts and that's normal so streamlining where the code should be is already a good gain.
  • QHttpServer with mutual TLS authentication

    Unsolved
    2
    0 Votes
    2 Posts
    584 Views
    S
    @tomas-soltys "I think I need to get access to QSslSocket which can then further provide certificate details" Find QHttpServer source code. I mean QHttpServer.cpp and QHttpServer.h Modify the code so that you can get QSslSocket object. Then you can use: QSslCertificate QSslSocket::peerCertificate() const "Returns the peer's digital certificate (i.e., the immediate certificate of the host you are connected to), or a null certificate, if the peer has not assigned a certificate.". I have question to you: what version of Qt and openssl you use. Look at my post: maybe you can help me to get read of ssl connection issue . Link: https://forum.qt.io/topic/150462/qhttpserver-api-https-openssl-letsencrypt-sslv3-alert-handshake-failure-alert-number-40/6?_=1697291376846