Skip to content
QtWS25 Call for Papers
  • 0 Votes
    5 Posts
    325 Views
    SavizS

    Hello again,

    I managed to fix the issue. I simply moved all my QAction objects to the other QToolBar since the designer did not allow me to reposition the tool bars.

    Thank you again.

  • 0 Votes
    4 Posts
    632 Views
    Chris KawaC

    Apparently separator will always fill the height of the toolbar (or width for vertical toolbars). You can limit it by adding top/bottom margins, so if your toolbar is 40px and you want the separator to be 30px add 5px top and bottom margins.

  • 0 Votes
    3 Posts
    573 Views
    M

    @Christian-Ehrlicher Thanks a lot, it is exactly what I was missing!

  • 0 Votes
    9 Posts
    838 Views
    jeremy_kJ

    @canol said in Removing a QGraphicsProxyWidget from QGraphicsScene crashes the app, but only when using a button on a toolbar:

    Hello, I have a medium sized app which had some random crashing problems. The crashes don't print any error messages. After a long investigation, getting rid of a lot of code, now I have a minimal example.

    For problems that don't appear to produce any usable output, turning on all QLoggingCategory categories can help. QT_LOGGING_RULES="*.*=true" python test.py should flood the console with information about what Qt is doing prior to the crash.

    In addition, installing a QObject::eventFilter() on the widget or QApplication can provide insight into how far input processing proceeded.

    class Filter(QObject): def __init__(self, target, *args, **kwargs): super().__init__(*args, **kwargs) target.installEventFilter(self) def eventFilter(self, target, event): print("Attempting to deliver {} to {}".format(event.type(), target)) return super().eventFilter(target, event) app = QtWidgets.QApplication([]) filter = Filter(app)

    The app has a QGraphicsView, and I add and remove QWidgets dynamically on the graphics view. The widgets have a toolbar, and the toolbar had a close button on it, which removes and deletes the widget from QGraphicsView. The crashes would randomly happen when I used this close button.

    Here is a complete example (it is a PySide2 program, I haven't tried it with C++):

    Porting the example to PyQt5 had crashes for the same input, on every attempt. Maybe PyQt is more aggressive in object reclamation than PySide.

    My questions are:

    **1) Why does it crash when I trigger the action using mouse click on the button?

    The issue appears to be a deletion of the recipient object while there are events for it remaining in the queue. As mentioned in the documentation for QObject::~QObject(), this is a problem.

    In C++, QObject::deleteLater() provides a convenient solution. Unfortunately, PySide and PyQt interfere by deleting the object when the last python reference is removed.

    Why does it NOT crash, when I use the keyboard shortcut for the action?**

    Different triggering mechanisms lead to a different sequence of events. If the last event triggers the action, deleting the object is fine. If there's a mouse release or a paint event after, deletion in the slot connected to the action is unsafe.

    The example above uses a QPushButton, instead of a QToolBar+QAction, and it does not crash. So another question:

    3) Why does it not crash when I use QPushButton instead of QToolBar+QAction?

    As with #2, the events delivered are probably different.

    This example won't crash. I guess waiting for the control to return to event loop before removing the item helps. So my final question is:

    4) Why does using QTimer.singleShot() helps here?

    Using QTimer.singleShot() schedules the slot for the next iteration of the event loop, after the currently pending events have been processed. The same thing can be accomplished using a queued connection for the action's slot instead of a 0-timer.

  • 0 Votes
    2 Posts
    301 Views
    Christian EhrlicherC

    As I already wrote on SO use selectionChanged() / itemSelectionChanged() signals ... when nothing is selected, you can't deselect items so how do you want to achieve a deselect here?

  • 0 Votes
    4 Posts
    1k 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
    5 Posts
    2k Views
    J

    @Rizwan94 May I ask what was your final implementation? I'm trying to setup a frameless window and add my title/close buttons on top of an existing QMainWindow (from .ui)
    Thanks in advance

  • 0 Votes
    5 Posts
    785 Views
    D

    @jsulm said in QActionWidget & QToolBar - no actionTriggered signal...:

    @Dariusz Maybe I'm blind but I can't find an addAction() overload with a QAction parameter. All I can see is:

    addAction(const QString &) : QAction * addAction(const QIcon &, const QString &) : QAction * addAction(const QString &, const QObject *, const char *) : QAction * addAction(const QIcon &, const QString &, const QObject *, const char *) : QAction * addAction(const QString &, Functor ) : QAction * addAction(const QString &, const QObject *, Functor ) : QAction * addAction(const QIcon &, const QString &, Functor ) : QAction * addAction(const QIcon &, const QString &, const QObject *, Functor ) : QAction * addActions(QList<QAction *> )

    https://code.woboq.org/qt5/qtbase/src/widgets/kernel/qwidget.cpp.html#_ZN7QWidget9addActionEP7QAction (press enter 2x in search input www as for some reason it does not scroll to right spot)

    Edit I just noticed I messed up title... corrected to QWidgetAction sorry!

  • Stacking toolbars?

    Unsolved General and Desktop
    3
    0 Votes
    3 Posts
    538 Views
    D

    @SGaist said in Stacking toolbars?:

    Hi,

    AFAIK, no there's not. What kind of interface are you looking for ?

    Hey

    Woah this one slipped my fingers...
    I think it would look like QTabWidget with only QToolbars as its children, each toolbar being 1 other widget. But with difference that that the QTab"ToolBar" would be a toolbar so I could place it like toolbar widget... ?

    Perhaps I will need to somehow extend QToolbar with QTabBar and somehow make it work mhmm

  • 0 Votes
    2 Posts
    516 Views
    SGaistS

    Hi,

    What about QGraphicsProxyWidget ?

  • 0 Votes
    9 Posts
    1k Views
    SGaistS

    QObject are not copiable, see here for the why.

  • 0 Votes
    1 Posts
    571 Views
    No one has replied
  • 0 Votes
    8 Posts
    2k Views
    A

    @ambershark I apologize for the late reply, I fell sick.
    Anyway, yea using StackWidget did the job.
    Thanks

  • QToolbar stylesheet

    Solved General and Desktop
    7
    0 Votes
    7 Posts
    5k Views
    Gianluca86G

    Ok, I tried this:

    // MyStyle.h #include <QStyle> class MyStyle : public QStyle { public: MyStyle(); virtual int pixelMetric(PixelMetric pm, const QStyleOption* option, const QWidget* widget) const ; }; // MYStyle.cpp #include "MyStyle.h" MyStyle::MyStyle() { } int MyStyle::pixelMetric(PixelMetric pm, const QStyleOption* option, const QWidget* widget) const { if (pm == QStyle::PM_ToolBarExtensionExtent) return 50; return QStyle::pixelMetric(pm, option, widget); }

    Is it correct?

    The line

    return QStyle::pixelMetric(pm, option, widget);

    give me this error:
    error: undefined reference to `QStyle::pixelMetric(QStyle::PixelMetric, QStyleOption const*, QWidget const*) const'

  • Add more toolbar

    Solved General and Desktop
    3
    0 Votes
    3 Posts
    745 Views
    Gianluca86G

    It works perfectly, thanks a lot.

  • 0 Votes
    3 Posts
    2k Views
    ErikaE

    @SGaist Thanks. That's definitely another option. I suppose these approaches are as good as it gets for having a toolbar item auto-adjust to horizontal vs. vertical. Thanks again.

  • 0 Votes
    2 Posts
    760 Views
    Chris KawaC

    Hi and welcome to the forum.

    This isn't directly supported, but you can achieve similar result if you make your central widget another QMainWindow. This has the downside that you can't move the toolbars between the two QMainWindows, unless you manage to reparent them dynamically while dragging (should be possible but I haven't tried it).

  • 0 Votes
    7 Posts
    2k Views
    SGaistS

    Depending on your needs you might be interested by DevMachines's QTitanRibbon which seems to be doing what you want. Note that it's a commercial product.

    What exactly are you trying to achieve with putting the scroll bar to the left ?

    There are already several applications written in QML for desktop. It really depends on what you want to do.

  • 0 Votes
    2 Posts
    5k Views
    VRoninV

    Did you try doing it outside of the QToolBar?

    QWidget* spinWidget = new QWidget; QHBoxLayout* spinLay = new QHBoxLayout(spinWidget); spinLay.addWidget(new QSpinBox(spinWidget)); spinLay.setContentsMargins(0,0,10,0); // Here you set the spacing QToolBar* toolbarDocument = new QToolBar; toolbarDocument->addWidget(spinWidget ); toolbarDocument->addWidget(new QComboBox); addToolBar(toolbarDocument);