Skip to content
QtWS25 Last Chance
  • Custom QCheckbox in QT widgets

    Unsolved General and Desktop qtwidgets qcheckbox stylesheet qtablewidget
    3
    0 Votes
    3 Posts
    925 Views
    EagleSparrowE
    Here is the code. QList<SomeClass> ModeTableEntries ; for (int row = 0; row < ModeTableEntries .length(); row++) { ui->EntriesTableWidget->insertRow(row); ui->EntriesTableWidget->setRowHeight(row, 45); ModeValues value = ModeTableEntries [row]; QTableWidgetItem* currentItem = new QTableWidgetItem(value .ModeText); if(TestModeEnabled == true) currentItem->setCheckState(Qt::Checked); else currentItem->setCheckState(Qt::Unchecked); ui->EntriesTableWidget->setItem( row, 0, currentItem); currentItem->setFlags(currentItem->flags()^(Qt::ItemIsEditable )); } The problem is that I cannot style the default implementation of the QTableWidgetItem(QCheckbox) that is part of the QTableWidgetItem.
  • 0 Votes
    4 Posts
    2k Views
    Pl45m4P
    @vicky_mac A QStackedWidget works like a book. You have pages with your content. You can flip these pages to change your widget inplace (without opening another window or something else). So one possibility is to put one of each QTabWidget (each with a different tabBar position) on a page of a QStackedWidget. You could flip the pages by clicking a dummy tab on each tabBar or you use a button to go to the next page. I know, this is not exactly what the widget in your image looks like :) @vicky_mac said in How to Add multiple Qtoolbar in QtabWidget: Haven't used QT much If you want a widget, that looks exactly like the one shown above, you could still try to subclass and create your own, custom TabWidget, but I fear, that it might be a little too challenging. Here's all you need to know about QStackedWidget (https://doc.qt.io/qt-5/qstackedwidget.html#details)
  • 0 Votes
    3 Posts
    1k Views
    mrjjM
    Hi As far as I know, there is nothing like that in Qt. It can blur widgets but not the actual desktop.
  • Align QPainterPath

    Unsolved General and Desktop qt 5.9.0 qtwidgets qlabe
    2
    0 Votes
    2 Posts
    1k Views
    G
    UPD: I write this method for drawing, looks good { QLabel::paintEvent(event); QPainter painter (this); painter.setPen(Qt::green); painter.setBrush(palette().windowText()); painter.setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing); painter.setFont(font()); QRect font_rect = painter.fontMetrics().boundingRect(text()); QRect label_rect = contentsRect(); label_rect.adjust(margin(), margin(), -margin(), -margin()); int dx = label_rect.width() - font_rect.width(); int dy = label_rect.height() - font_rect.height(); int x = 0; int y = 0; if (alignment() & Qt::AlignLeft) x = label_rect.left(); else if (alignment() & Qt::AlignHCenter) x = label_rect.left() + dx / 2; else if (alignment() & Qt::AlignRight) x = label_rect.right() - font_rect.width(); if (alignment() & Qt::AlignTop) y = label_rect.top() + font_rect.height(); else if (alignment() & Qt::AlignVCenter) y = label_rect.top() + dy / 2; else if (alignment() & Qt::AlignBottom) y = label_rect.bottom(); QPainterPath path; path.addText(x, y, font(), text()); painter.fillPath(path, palette().windowText()); painter.strokePath(path, QPen(QColor(255, 0, 0, 50), 2)); } [image: c4d954bb-bb48-4afc-ba4d-b461172f0f61.png] But i still dont understand the difference btw native paint event and my own
  • Seeking inspiration for direction orientation.

    Unsolved General and Desktop qtwidgets orientation
    3
    0 Votes
    3 Posts
    877 Views
    raven-worxR
    @Faruq QML (using Canvas element) and QtQWidgets (using QPainter in combination with QPainterPath) is capable of drawing such things. In either way it's all about the math and doing the calculations of each shape (arcs, lines, texts, ...) The bottom image is rather easy. Yyou just need to calculate the translation along the x-axis based on your input values which make up the direction.
  • 0 Votes
    25 Posts
    10k Views
    SGaistS
    Don't @ the moderators unless you have an issue requiring moderation. Depending on the content of your line edit, you can use toLatin1() or toUtf8() rather than making these two conversions.
  • 0 Votes
    6 Posts
    3k Views
    V
    Thank you all, the issue is solved.
  • Qt Widgets global stylesheet

    Solved General and Desktop qtwidgets stylesheet
    8
    0 Votes
    8 Posts
    13k Views
    G
    If you want stylesheet ready for the use of qss in your application use this site: https://qss-stock.devsecstudio.com
  • Get margins of QPushButton

    Solved General and Desktop qtwidgets qss
    13
    1 Votes
    13 Posts
    12k Views
    C
    @goldstar2154 Totally agree with you - there is a obvious bug. But thanks to @raven-worx 's code we've got a way to get a result at least. And "solved" will help in web search:) Thank you very much for this question:)
  • 0 Votes
    10 Posts
    7k Views
    mrjjM
    @IMAN4K Hi Im not sure what "material ripple animation" really is so its hard to say which design i would prefer. Copying Paint of QMenu would be last choice as there might be bugs and its involving to keep in sync. If the items can do all the drawing them self i would go for that. (2 i think :)
  • 1 Votes
    11 Posts
    8k Views
    P
    Thank you! Yes, InputPanel was what was needed to make the VirtualKeyboard actually show on embedded (eglfs_kms or wayland). Then it also needs a y and width. And then it is always visible by default, so I guess need to bind visible: active. The code shown on this page, i.e. without InputPanel, "just worked" on desktop (except the virtual keyboard was massive), but not embedded https://doc.qt.io/qt-6/qtvirtualkeyboard-basic-example.html and the "Detailed Description" here didn't really explain why/when to use it https://doc.qt.io/qt-6/qml-qtquick-virtualkeyboard-inputpanel.html
  • 0 Votes
    10 Posts
    5k Views
    kshegunovK
    @fortyff said in Undefined referance to class::function: There are the same errors occured in the "esimplelabel.cpp" file, but I didn't write down here, since it'll consume too much place. Make sure you have all virtual functions that are declared defined. While a declaration of a regular function without a definition is perfectly valid (until it's called), that's not true for virtual methods.
  • 0 Votes
    9 Posts
    10k Views
    Z
    I finally managed to get custom colors. I gave my QTreeView an object name to be able to write this in CSS: m_treeView->setObjectName("MyTreeView"); m_treeView->setStyleSheet("QTreeView#MyTreeView::item {color: none;}"); basically now my model controls text color through Qt::ForegroundRole regardless of the application's CSS. I feel like it's the wrong place to put theming, but it works for me at the moment. Well... until we decide to have different themes :-°
  • Using a Qt 5 Widget within a QML application?

    Unsolved General and Desktop qt5.5 qtwidgets
    5
    0 Votes
    5 Posts
    9k Views
    alex_spataruA
    Here is a method of capturing mouse events and wheel events based on the previous answer. Unfortunately, this method requires us to access protected members of the QWidget. I don't know how legal it is, but it works: Constructor: QmlPlainTextEdit::QmlPlainTextEdit(QQuickItem *parent) : QQuickPaintedItem(parent) { // Set item flags setFlag(ItemHasContents, true); setFlag(ItemAcceptsInputMethod, true); setFlag(ItemIsFocusScope, true); setAcceptedMouseButtons(Qt::AllButtons); // Initialize the text edit widget m_textEdit = new QPlainTextEdit(); m_textEdit->installEventFilter(this); m_textEdit->setVerticalScrollBarPolicy(Qt::ScrollBarAsNeeded); // Set the QML item's implicit size auto hint = m_textEdit->sizeHint(); setImplicitSize(hint.width(), hint.height()); // Resize QPlainTextEdit to fit QML item connect(this, &QQuickPaintedItem::widthChanged, this, &QmlPlainTextEdit::updateWidgetSize); connect(this, &QQuickPaintedItem::heightChanged, this, &QmlPlainTextEdit::updateWidgetSize); } Events: bool QmlPlainTextEdit::event(QEvent *event) { switch (event->type()) { case QEvent::FocusIn: forceActiveFocus(); return QQuickPaintedItem::event(event); break; case QEvent::Wheel: processWheelEvents(static_cast<QWheelEvent*>(event)); return true; break; case QEvent::MouseButtonPress: case QEvent::MouseButtonRelease: case QEvent::MouseButtonDblClick: case QEvent::MouseMove: processMouseEvents(static_cast<QMouseEvent*>(event)); return true; break; default: break; } return QApplication::sendEvent(m_textEdit, event); } Event filter: bool QmlPlainTextEdit::eventFilter(QObject *watched, QEvent *event) { Q_ASSERT(m_textEdit); if (watched == m_textEdit) { switch (event->type()) { case QEvent::Paint: case QEvent::UpdateRequest: update(); break; default: break; } } return QQuickPaintedItem::eventFilter(watched, event); } Paint function: void QmlPlainTextEdit::paint(QPainter *painter) { if (m_textEdit && painter) m_textEdit->render(painter); } Process mouse/wheel events: Doing some tests, I found out that QPlainTextEdit::event() returned false for mouse and wheel events. The quick and dirty solution was to call the appropriate event handlers directly. However, these functions are protected, so we need to do some unorthodox things in order to call these functions: void QmlPlainTextEdit::processMouseEvents(QMouseEvent* event) { class Hack : public QPlainTextEdit{ public: using QPlainTextEdit::mousePressEvent; using QPlainTextEdit::mouseMoveEvent; using QPlainTextEdit::mouseReleaseEvent; using QPlainTextEdit::mouseDoubleClickEvent; }; auto hack = static_cast<Hack*>(m_textEdit); switch(event->type()) { case QEvent::MouseButtonPress: hack->mousePressEvent(event); break; case QEvent::MouseMove: hack->mouseMoveEvent(event); break; case QEvent::MouseButtonRelease: hack->mouseReleaseEvent(event); break; case QEvent::MouseButtonDblClick: hack->mouseDoubleClickEvent(event); break; default: break; } } void QmlPlainTextEdit::processWheelEvents(QWheelEvent* event) { class Hack : public QPlainTextEdit{ public: using QPlainTextEdit::wheelEvent; }; static_cast<Hack*>(m_textEdit)->wheelEvent(event); } Resize widget to fit QML item: void QmlPlainTextEdit::updateWidgetSize() { m_textEdit->setGeometry(0, 0, static_cast<int>(width()), static_cast<int>(height())); update(); } To use this class in QML, add in main.cpp: qmlRegisterType<QmlPlainTextEdit>("QtWidgets", 1, 0, "QmlPlainTextEdit"); And finally, the QML item would be used like: QmlPlainTextEdit { id: textEdit focus: true Layout.fillWidth: true Layout.fillHeight: true onFocusChanged: { textEdit.forceActiveFocus() } } If anybody has a better way to process mouse/wheel events for this scenario, please post it here. I was stuck with this issue for three days and this is the only solution that I found.
  • 0 Votes
    4 Posts
    6k Views
    SGaistS
    You'r welcome ! Since you have it working now, please mark the thread as solved using the "Topic Tool" button so other forum users may know a solution has been found :)
  • 1 Votes
    1 Posts
    946 Views
    No one has replied
  • Subwindows on MainWindow

    General and Desktop qtwidgets
    5
    0 Votes
    5 Posts
    6k Views
    A
    Hi Lays, when you already have a layout set, you don't need to create a new one. Just access your existing Layout with the layout() function. In general every QWidget has its own layout (there are different kinds of layouts) and you can add widgets to them. So if you want to add a widget to your QMainWindows layout you can call inside your main windows code something like this: this->layout()->addWidget(new Widget); For further information please read http://doc.qt.io/qt-4.8/layout.html. Greetings AlexRoot
  • Your software deserves a great interface!

    Jobs design qml qtwidgets
    4
    0 Votes
    4 Posts
    2k Views
    JKSHJ
    Nice! Thanks for sharing :)