In QWindow there is a signal windowStateChanged(Qt::WindowState).
I'm looking for similar signal in QMainWindow. Is it available?
I need it to notify toolbar about fullscreen change, as I have a checkable toolbar button which changes window to fullscreen when user clicks it. However when user changes to fullscreen bypassing the button, it shows invalid state.
QMainWindow inherits from QWidget where you find the ::setWindowState(Qt::WindowStates) method. In its docs, it says:
When the window state changes, the widget receives a changeEvent() of type QEvent::WindowStateChange.
So it seems like you have to override changeEvent() to handle this, I don't think there is a signal.
Related
So basically i have a class that inherits from QMainWindow and there's a toolbar action in my mainwindow that calls another small window where the user puts in some info, i want the mainwindow inaccessible i.e you shouldn't be able to click on it or interact with it unless you finish what you're doing on that small window or you close the small window. setWindowFlags(Qt::WindowStaysOnTopHint); only makes the small window be on top, but i can still access the MainWindow.
Looks like all i needed was the setWindowModality(Qt::ApplicationModal); method
In QMainWindow, when few widgets are tabbed together in dock area, how can I detect when a tab has been toggled by user? It is not a problem when I have an instance of QTabWidget created by myself and can attach a handler to currentChanged(), but what's about this case when the main window internally performs docking/tabifying operations? It normally would be showEvent() triggered but by some reason it doesn't work when tabs are switched. Also, a widget, not on active tab, has it's visibility state turned ON (isVisible() returns true) which is strange.
I found the answer. It is QMainWindow::tabifiedDockWidgetActivated() which is signaled when a tab on a docked widget changes. It was added in Qt 5.8. Without it there is no way.
I have my custom widget inherited from QWidget, and I've connected the widget's menu-calling signal to my slot.
connect(m_ontologyView, SIGNAL(customContextMenuRequested(QPoint)), SLOT(showContextMenuSlot(QPoint)));
Now I want user to be able to change button calling the context menu. Normally it's called with right mouse button, but how do I tell the widget to call the menu with a button of my choice?
I'm on Qt 5.4.0
Instead of using QWidget::customContextMenuRequested, you will need to reimplement the widgets mouse event functions, QWidget::mousePressEvent, QWidget::mouseReleaseEvent and QWidget::mouseMoveEvent. Inside of these events, you can then show you menu using QMenu::popup. (The point can be extracted from the mouse events).
I was trying to use a shape changing dialog box i.e., when I click on a button the size of the dialog box should become big with the extra details. In order to do that I wrote the following code on button:
QObject::connect(ui->moreButton, SIGNAL(toggled(bool)),
ui->sgroupBox, SLOT(setVisible(bool)));
but there are no changes happening on my dialog box. What should I do in this case.
I had hidden the extra details by placing them in a grid using hide() function. The extra details are getting hidden but the size of widget is not getting changed.
Please help me with a solution
If I understand your question correctly you are trying to resize your QDialog box after clicking on a button in your user interface?
Since a QDialog inherits from a QWidget, you are able to call the QWidget::resize(int width, int height) method.
So now, to make the QDialog grow when you press the button you simply need to connect the toggled(bool) signal to a slot which then calls resize.
ie.
QObject::connect(ui->moreButton, SIGNAL(toggled(bool)), whateverClassManagesYourQDialog, onButtonToggled(bool));
Then implement this slot in your class that manages your QDialog:
ie.
// This is a slot in your class which implements QDialog
whateverClassManagesYourQDialog::onButtonToggled(bool toggledState){
ui->sGroupBox.setVisible(toggledState); // This will show or hide sGroupBox
resize(someIncrement,someIncrement); // This will grow your QDialog
}
I've recently been studying Qt, and have the following questions:
What is the difference between QAction and QToolButton?
How do I know when to override QPushButton? For example, should I override in order to be informed when the mouse enters a QPushButton's bounds? I don't need to in order to get the signal click().
Question 1:
QActions are used to define tasks performed by an application in a way which can be understood by a number of different user interface objects. Using an example from the Qt docs for context:
A QAction is defined; it is given an icon image, a text description, a keyboard shortcut and a longer tooltip description, as well as being linked to a user defined function.
newAct = new QAction(QIcon(":/images/new.png"), tr("&New"), this);
newAct->setShortcuts(QKeySequence::New);
newAct->setStatusTip(tr("Create a new file"));
connect(newAct, SIGNAL(triggered()), this, SLOT(newFile()));
Later in the implementation, the QAction is added both to a textual menu bar...
fileMenu->addAction(newAct);
... and an icon-based tool bar:
fileToolBar->addAction(newAct);
The menu bar uses the text description to create an entry in the menu corresponding to the action. Similarly the toolbar uses the icon set on the QAction to create an icon in the toolbar which corresponds to the action. Selecting the menu item, clicking the toolbar icon or pressing the keyboard shortcut will all result in the same effect: that defined by the linking of QAction::triggered() to newFile().
So to directly answer your question: a QAction is an abstract way of defining the various parameters and behaviour of a particular task performed by the application. A QToolbarButton is a UI object (derived from QWidget) created by a QToolbar in response to QToolbar::addAction()
Question 2:
Yes, QPushButton has a clicked() signal inherited from QAbstractButton, but it does indeed lack a way to inform when the mouse has entered its bounds. You have a couple of options in order achieve this, but first you need to first set the mouseTracking property to be enabled. This will allow you to receive mouse move events on the QPushButton even if no mouse buttons are pressed. With that done you need to explore one of the following options:
As you suggest, you could subclass QPushButton and reimplement mousePressEvent in order to respond to the mouse position.
You could install another widget as an eventFilter on the QPushButton, and watch for events of type (QEvent::MouseMove).