Skip to content
  • Custom widget with designer

    Unsolved General and Desktop custom widget designer widget
    1
    0 Votes
    1 Posts
    475 Views
    No one has replied
  • 0 Votes
    7 Posts
    1k Views
    SGaistS
    You _vbox variable is now useless, you should remove it. Passing a parent to a layout when creating it automatically applies that layout to the parent. That's not what you want here (beside the fact that there are no use in setting a widget on a QMainWindow object.
  • 0 Votes
    5 Posts
    3k Views
    SGaistS
    Thanks for the detailed deep dive !
  • 1 Votes
    7 Posts
    3k Views
    Chris KawaC
    Since applications using burger menus usually have a very distinctive style I didn't want to make any assumptions. The look of the menu is up to you to style, it only implements the functionality. Same goes for the burger icon, you can set it to whatever you want, either the one included in the project or your own. There's an example in the repo showing how to style it. As for actions - you can add an existing QAction or let the widget create one for you using any of the overloads of addMenuAction. In any case it returns a QAction* and you can connect to its triggered signal just as you would with any other action in the built-in Qt menus. Alternatively you can tag these actions in any way you want and only make a single connection to the BurgerMenu::triggered signal. You will get an action that was triggered as a parameter. One way to tag an action is by using QAction::setData or you can just store the action pointers somewhere when creating them and identify the action by the pointer, text, some property or whatever fits you. on_actionName_triggered() looks like a slot name created for the the auto-connection feature. If you want to use it you can do that too (although I wouldn't reccomend it). Just create your actions in the designer via its action editor and make your slots names match, just like you would with any normal menus/actions. The only caveat is that you need to manually add these actions to the menu from code, as there's no way to do that in the designer, but that's not a huge problem. So those are a couple of the most straightforward options out of couple more. It's deliberately left very flexible so you can use it however fits your overall application design best.
  • 0 Votes
    2 Posts
    599 Views
    J.HilkJ
    @leonardoMB https://doc.qt.io/qt-5/qwidget.html#setParent https://doc.qt.io/qt-5/qlayout.html#addItem (or addWidget)
  • 0 Votes
    6 Posts
    2k Views
    T
    @Maluna34 said in Add space between toolbar and dock widgets: @Tink It does not work. :( I'm sorry, my last remark was non-sensical since a dockwidget is not part of the centralwidget. This is probably some very specific dockwidget stuff that i don't know about. Perhaps some of the guru's here will know if it's possible.
  • 0 Votes
    6 Posts
    2k Views
    SGaistS
    So you want a modal dialog that is in fact loaded within a widget inside your QMainWindow class ? You can manually set the modality of your dialog with setModal.
  • QLabels have same width regardless of text?

    Unsolved General and Desktop qlabel layout widget
    9
    0 Votes
    9 Posts
    4k Views
    H
    @eyllanesc Oh I see, it's working now. Thank you!
  • Drag & Drop d'un Widget

    Solved French drag&drop widget drag and drop
    5
    0 Votes
    5 Posts
    1k Views
    M
    J'ai fini par réussir à partir de l'exemple cité ci-dessu. Voici le code : mainwidget.h #ifndef WIDGETPARENT_H #define WIDGETPARENT_H #include <QObject> #include <QtWidgets> #include <QPainter> #include <QPen> QT_BEGIN_NAMESPACE class QDragEnterEvent; class QDropEvent; QT_END_NAMESPACE class MainWidget : public QWidget { Q_OBJECT public: explicit MainWidget(QWidget *parent = nullptr); protected: void paintEvent(QPaintEvent *event) override; void dragEnterEvent(QDragEnterEvent *event) override; void dragMoveEvent(QDragMoveEvent *event) override; void dropEvent(QDropEvent *event) override; void mousePressEvent(QMouseEvent *event) override; signals: public slots: }; #endif // WIDGETPARENT_H mainwindow.h #ifndef MAINWINDOW_H #define MAINWINDOW_H #include <QObject> #include <QWidget> class MainWindow : public QWidget { public: explicit MainWindow(QWidget *parent = nullptr); protected: }; #endif // MAINWINDOW_H movable_child_widget.h #ifndef MOVABLE_CHILD_WIDGET_H #define MOVABLE_CHILD_WIDGET_H #include <QtWidgets> #include <QLabel> class Movable_Child_Widget : public QLabel { public: Movable_Child_Widget(const QString &text, QWidget *parent); QString labelText() const; private: QString m_labelText; }; #endif // MOVABLE_CHILD_WIDGET_H main.cpp #include <QApplication> #include "mainwindow.h" int main(int argc, char *argv[]) { QApplication app(argc, argv); #ifdef QT_KEYPAD_NAVIGATION QApplication::setNavigationMode(Qt::NavigationModeCursorAuto); #endif MainWindow window; bool smallScreen = QApplication::arguments().contains(QStringLiteral("-small-screen")); if (smallScreen) window.showFullScreen(); else window.show(); return app.exec(); } mainwidget.cpp #include "mainwidget.h" #include "movable_child_widget.h" static inline QString MemeFamilleDeProgrammes() { return QStringLiteral("application/x-ceTypeDeProgramme"); } // MemeFamilleDeProgrammes définit un type personnalisé de données à transmettre au presse papier. // Si deux occurences de ce même programme sont lancées, il sera ainsi possible de passer des widgets // d'un programme à l'autre. MainWidget::MainWidget(QWidget *parent) : QWidget(parent) { this->setFixedWidth(1000); this->setFixedHeight(100); Movable_Child_Widget *newChild = new Movable_Child_Widget("Child widget", this); newChild->setAttribute(Qt::WA_DeleteOnClose); QPalette pal = QPalette(); this->setGeometry(0, 0, 600, 100); pal.setColor(QPalette::Window, QColor("#CC773C")); this->setAutoFillBackground(true); this->setPalette(pal); setAcceptDrops(true); // <------------------------ Important de le mettre dans le parent du widget à déplacer } void MainWidget::paintEvent(QPaintEvent *event) { Q_UNUSED(event); QPainter painter(this); painter.setPen(Qt::blue); //painter.setBrush(QBrush("#539e47")); painter.drawRect(0, 0, this->width()-1, this->height()-1); // on place les quarts d'heures QPen pen0(Qt::green); pen0.setWidth(1); pen0.setStyle(Qt::DashDotLine); painter.setPen(pen0); for (int i=0; i<=24*4; i++){ painter.drawLine(int (i*this->width()/96),int (0.5*this->height()-10), int (i*this->width()/96), int (0.5*this->height()+10)); } // on place les heures QPen pen1(Qt::blue); pen1.setWidth(3); painter.setPen(pen1); //painter.setPen(Qt::blue); for (int i=0; i<=24; i++){ painter.drawLine(int (i*this->width()/24), int (0.5*this->height()-10), int (i*this->width()/24), int (0.5*this->height()+10)); } //updateGeometry(); } void MainWidget::dragEnterEvent(QDragEnterEvent *event) { if (event->mimeData()->hasFormat(MemeFamilleDeProgrammes())) { if (children().contains(event->source())) { event->setDropAction(Qt::MoveAction); event->accept(); } else { event->acceptProposedAction(); } } else if (event->mimeData()->hasText()) { event->acceptProposedAction(); } else { event->ignore(); } } void MainWidget::dragMoveEvent(QDragMoveEvent *event) { if (event->mimeData()->hasFormat(MemeFamilleDeProgrammes())) { if (children().contains(event->source())) { event->setDropAction(Qt::MoveAction); event->accept(); } else { event->acceptProposedAction(); } } else if (event->mimeData()->hasText()) { event->acceptProposedAction(); } else { event->ignore(); } } void MainWidget::dropEvent(QDropEvent *event) { if (event->mimeData()->hasFormat(MemeFamilleDeProgrammes())) { const QMimeData *mime = event->mimeData(); QByteArray itemData = mime->data(MemeFamilleDeProgrammes()); QDataStream dataStream(&itemData, QIODevice::ReadOnly); QString text; QPoint offset; dataStream >> text >> offset; Movable_Child_Widget *newChild = new Movable_Child_Widget(text, this); newChild->move(event->pos() - offset); newChild->show(); newChild->setAttribute(Qt::WA_DeleteOnClose); if (event->source() == this) { event->setDropAction(Qt::MoveAction); event->accept(); } else { event->acceptProposedAction(); } } else if (event->mimeData()->hasText()) { QStringList pieces = event->mimeData()->text().split(QRegularExpression(QStringLiteral("\\s+"))); QPoint position = event->pos(); for (const QString &piece : pieces) { Movable_Child_Widget *newChild = new Movable_Child_Widget(piece, this); newChild->move(position); newChild->show(); newChild->setAttribute(Qt::WA_DeleteOnClose); position += QPoint(newChild->width(), 0); } event->acceptProposedAction(); } else { event->ignore(); } } void MainWidget::mousePressEvent(QMouseEvent *event) { Movable_Child_Widget *child = static_cast<Movable_Child_Widget*>(childAt(event->pos())); if (!child) return; QPoint hotSpot = event->pos() - child->pos(); QByteArray itemData; QDataStream dataStream(&itemData, QIODevice::WriteOnly); dataStream << child->labelText() << QPoint(hotSpot); QMimeData *mimeData = new QMimeData; mimeData->setData(MemeFamilleDeProgrammes(), itemData); mimeData->setText(child->labelText()); QDrag *drag = new QDrag(this); drag->setMimeData(mimeData); const QPixmap *ch = child->pixmap(); drag->setPixmap(*ch); drag->setHotSpot(hotSpot); child->hide(); //if (drag->exec(Qt::MoveAction | Qt::CopyAction, Qt::CopyAction) == Qt::MoveAction) if (drag->exec(Qt::MoveAction)) child->close(); else child->show(); } mainwindow.cpp #include "movable_child_widget.h" #include "mainwindow.h" #include "mainwidget.h" MainWindow::MainWindow(QWidget *parent) : QWidget(parent) { setWindowTitle(tr("Fenêtre principale")); // QPalette newPalette = palette(); // Fenêtre principale newPalette.setColor(QPalette::Window, Qt::gray); // setPalette(newPalette); // this->setWindowState(Qt::WindowMaximized); // this->setFixedSize(2000, 1000); // MainWidget *Widget1 = new MainWidget(this); // Création d'un premier widget Widget1->move(200, 200); // MainWidget *Widget2 = new MainWidget(this); // Création d'un second widget Widget2->move(200, 400); // } movable_child_widget.cpp #include "movable_child_widget.h" Movable_Child_Widget::Movable_Child_Widget(const QString &text, QWidget *parent) : QLabel(parent) { QFontMetrics metric(font()); QSize size = metric.size(Qt::TextSingleLine, text); QImage image(size.width() + 12, size.height() + 12, QImage::Format_ARGB32_Premultiplied); image.fill(qRgba(0, 0, 0, 0)); QFont font; font.setStyleStrategy(QFont::ForceOutline); QLinearGradient gradient(0, 0, 0, image.height()-1); gradient.setColorAt(0.0, Qt::white); gradient.setColorAt(0.2, QColor(200, 200, 255)); gradient.setColorAt(0.8, QColor(200, 200, 255)); gradient.setColorAt(1.0, QColor(127, 127, 200)); QPainter painter; painter.begin(&image); painter.setRenderHint(QPainter::Antialiasing); painter.setBrush(gradient); painter.drawRoundedRect(QRectF(0.5, 0.5, image.width()-1, image.height()-1), 25, 25, Qt::RelativeSize); painter.setFont(font); painter.setBrush(Qt::black); painter.drawText(QRect(QPoint(6, 6), size), Qt::AlignCenter, text); painter.end(); QPushButton *bt = new QPushButton ("bt", this); bt->move(this->width()/2, 0); setPixmap(QPixmap::fromImage(image)); m_labelText = text; } QString Movable_Child_Widget::labelText() const { return m_labelText; }
  • How to use SVG

    Unsolved General and Desktop svg icon widget
    33
    0 Votes
    33 Posts
    21k Views
    SMEasyS
    As explained here, QSvgWidget has been moved to a new module called QtSvgWidgets. According to the documentation: Header: #include <QSvgWidget> CMake: find_package(Qt6 REQUIRED COMPONENTS SvgWidgets) target_link_libraries(mytarget PRIVATE Qt6::SvgWidgets) qmake: QT += svgwidgets Inherits: QWidget So in Qt6 the solution is following: QT += svgwidgets
  • Enable child widgets

    Solved General and Desktop widget
    2
    0 Votes
    2 Posts
    491 Views
    mrjjM
    Hi I think top-level widgets refer to "Windows" . as in the floating kind. So maybe it says that it won't disable them even if it technically is kinda a child ? Is it the general rule that property-states are applied to every child widget if they are not explicitly set to a different state? Its by design choice when a common state makes sense. so no, it's not a rule. which situations I have to set widget properties for every childwidget explicit. Mostly when your apps design requires such. Like same color of x items. Not so much for QWidgets standard behavior with enable/show/hide/scale.
  • 0 Votes
    9 Posts
    9k Views
    SGaistS
    Use QScreen::availableGeometry. It provides the geometry excluding window manager reserved areas.
  • Adding right click menu on QTableWidget

    Unsolved General and Desktop qt5 widget table widget
    9
    0 Votes
    9 Posts
    6k Views
    D
    @nagesh said in Adding right click menu on QTableWidget: @suslucoder if you want to create the chart only during right click, comment above lines from constructor. grafik_olustur(); //create chart first timer->start(500); //adds values to chart this was the answer im searching for. Sorry for, i couldnt explain my question clearly.
  • 0 Votes
    3 Posts
    764 Views
    EmrecpE
    @jsulm I think this is for C++, I don't know how to use it on Python?
  • Mcu and Serial Communications

    Unsolved General and Desktop serial widget qt5
    7
    0 Votes
    7 Posts
    1k Views
    D
    @jsulm Yes i know. Thank you for answering.
  • Push buttons on the buttom like a tab

    Unsolved General and Desktop qtabwidget widget push button
    7
    0 Votes
    7 Posts
    1k Views
    D
    @jsulm Thank you
  • Close the widget when push the button

    Solved General and Desktop qt5 pushbutton widget
    3
    0 Votes
    3 Posts
    1k Views
    JonBJ
    @suslucoder said in Close the widget when push the button: want to close the widget when i clicked on Ok button. What widget (do you want to close)?
  • 0 Votes
    3 Posts
    886 Views
    aha_1980A
    @jsulm That is correct, but I'd first try with the latest Qt 5 version 5.15.2 Regards
  • 0 Votes
    8 Posts
    16k Views
    JonBJ
    @suslucoder If you changed anything in ui_mainwindow.h this could happen. If you get what seems like an inexplicable error when compiling, wiping the output directory can sometimes resolve. However, this does not apply to normal, run-of-the-mill errors!