Non-clickable QPushButton - c++

I've been trying to make a Qt test app to put two different 'scenes' in, using one main widget which is the window which can hide and show the two other widgets which are the different scenes. In scene 1, there is a QPushButton, which is connected to a signal which is connected to showing scene 2. However, when I click the button, nothing happens. I tried running in debug mode, and the first slot isn't fired, AND the animation of pushing the button down isn't triggering. Is this something to do with the fact that the button is inside a widget inside a widget? I'll add the code if necessary.

Related

QAction with icon displays checkbox on top

I have a menu with checkable QActions in it: (ed: these calls are within a QWidget subclass, so 'this' points to the associated widget).
QAction* action = new QAction(icon, actionName, this);
action->setCheckable(true);
action->setActionGroup(m_actionGroup);
menu->addAction(action);
This menu is attached to a tool button, which is in a QWidget with a few other tool buttons. Previously, it was part of a larger widget, but I've been refactoring to confine some things together.
When it was previously part of the larger widget, these actions and their icons displayed fine. Now, however, the icons are drawn in a dotted pattern and a box for a check box is drawn on top. When I hover over an action, the dotted action goes away entirely, and it's just the check box. When I select an action, the icon appears normally.
I've tried doing the same in a little toy program, and the menu displays correctly then, so I'm having trouble reproducing the issue outside of my rather large program. Has anyone seen behaviour like this before, or know how to fix it?
Qt 5.5 on Ubuntu 16.04 is the platform information.
Edit: It gets even stranger. The original implementation created the QMenus without parents. Which I would have avoided because of memory leak concerns. But if you create the menu with the widget holding the button as a parent, then you get this behaviour. It's something about the QMenu being constructed with a parent that is creating issues, not the QAction.

Detect widget change in QStackedWidget

I have a GUI that is to be put on a screen that has hardware buttons which map onto function keys. When a top row key is pressed the idea is that the screen will change to a different view of the data with the side buttons mapping into the view currently displayed and displaying corresponding information on screen (button, or label).
I have a top-level widget that contains these buttons and a stacked widget with the different data view (widgets) inside. I can navigate within the stacked widget from the QMainWindow but I cannot work out how the widget knows it no longer has focus so I can pause updates to the data, and given one of these views is video data I don't want it to be constantly updating in the background. Is it reasonable here for the MainWindow to just disconnect all signals, change the widget and then make new connections or is there a better Qt approach? I didn't necessarily want such tight coupling as the view itself knows what it should display on the buttons, not the main window.
I tried overriding focusInEvent(QFocusEvent* e) in the children of the stacked widget but it is never called.
Your QStackedWidget has a signal currentChanged(int index), this signal is fired everytime the current displayed widget on the QStackedLayout changes, can't you use this signal to toggle a flag on the widget displaying video to not to render it?
Whent he currentWidget is the video widget you can resume the rendering of the data( imaghe ) supplied to it, else you can simply discard the data given to it and save CPU cycles by not rendering it?
Am I missing something here?

Qt: Setting up buttons on a splash screen

I have a splash screen set up like so, (the QApplication was declared earlier):
QSplashScreen *splash = new QSplashScreen;
splash->setPixmap( QPixmap("image.png" ) );
splash->show();
What I would like to know ifs if there is a way in Qt that allows buttons to be attached to the splash screen. I would like to have some sort of user interaction on the splash screen itself.
Since QSplashScreen class inherits from QWidget class, you probably can access the most of capabilities a QWidget provides e.g. adding child widgets.
However, you should be aware of the following notice pointed to by the doc.
Since the splash screen is typically displayed before the event loop has started running, it is necessary to periodically call QApplication::processEvents() to receive the mouse clicks.
Therefore after registering the click event of that button you should periodically call QApplication::processEvents() or (qApp->processEvents()) during your app initialization to allow the app to handle click events.

Qt/C++ Technique To Show Inline Dialog

I have QtCreator 5.5 for the Mac, using C++, and I'm new at this. I have a MainForm window. I want to show a dialog inside that but draw it separately in its own UI designer. Then, at runtime, my code will pull that other UI and show it inside that window.
Imagine for instance a main application window. You click a button and you need to see a confirmation dialog. Normally you could do that with a separate window. Instead, I want it to be inline at runtime, to show it like a widget on the main window.
Sure, I could draw my dialog on top my existing window in a widget, but that defeats the point where I want to be able to adjust it in its own designer window, and just load it as necessary in the main window when I need it.
What's the technique in QtCreator and C++ to do this?
Open QtCreator. This task can only be done through there.
Assuming you have a regular Qt Widget Application, you need to just add a QWidget control on the MainWindow's centralWidget in the UI Designer.
Next, click Edit in the UI Designer and then rightclick Forms. Choose Add New...
In the dialog that opens up, choose Qt > Qt Designer Form Class, and click Choose...
Select Widget and then go with the defaults on the rest. This creates a widget called Form, and the form.h and form.cpp will also be added to your project.
Now find the form.ui and open it in Qt Designer. Add a Stacked Widget Control on the QWidget form. Size it to the same size as the parent widget. Next, stick a Label Control on the Stacked Widget Control's first page. This label will be temporary just to prove that this works. You'll set it to the text of "Testing". Now close the designer.
Flipping back to your UI File of your Main Window, find that QWidget you added and rightclick it. Choose Promote... and a dialog box appears. In that dialog, set Promoted Class Name to Form and then set Header File to form.h. Leave everything else on defaults and click Add and then Promote.
You may be expecting to see an immediate change in your Main Window in that QWidget that you added previously. However, that's not how this works unfortunately. You only see the change at runtime. So, now you should Run your application in Qt Creator. You'll see when it runs that your widget now contains the contents of that form.ui component you created.
Now, here's where it gets interesting. You can now draw all your inline modal dialogs on that form.ui, just putting them on different pages of your Stacked Widget control. You can also set the properties of your widget so that the background of the QWidget container is opaque and dark (creating a background dimmer) and then, at runtime, resize the QWidget to the size of your Main Window. When you need to switch to a different dialog, you can use setCurrentWidget() or setCurrentIndex() on that StackedWidget item like so:
QStackedWidget *w = ui->widget->findChild<QStackedWidget *>("stackedWidget");
w->setCurrentIndex(1);
In that example, I had a QWidget control on my MainWindow named simply widget. I then found the control on it called stackedWidget. Once I had it, I used the setCurrentIndex(x) method on it to change the page of that widget to show the one I needed. Remember that this is a zero-based index. So, (1) would be page 2.
QMainWindow::setCentralWidget
Inside your QMainWindow constructor add:
MyDialogClass myDialog = new MyDialogClass();
setCentralWidget(myDialog);

QPushButton is inactive till MainWindow gets focus

I have a QMainWindow with three QPushButtons (arranged in a QVBoxLayout in a QWidget). All have the same properties, except objectName, icon and iconSize. All are enabled and have two icons, one for normal and one for disabled.
When I start my application, always the top most icon shows the disabled icon (but is working, so it is enabled) the other two are fine. As soon as a focusable control in that window gets the focus, the icon changes to the active one and everything is fine.
Calling update or repaint in the showEvent of the window doesn't help either.
I'm using gcc 4.8.1 and qt 5.1.0.
Any ideas how to handle this glitch?
Update: It gets more strange: Starting the program, the icon shows disabled, getting another application the focus, the icon shows enabled, bringing the window on top again without giving it the focus (e.g. by using the task bar) changes the icon back to diabled. Clicking a control in the window, which can have focus will fix it again.
Well, well I finally got it. I just set the focus manually in the code and realized, that the icons were set in a wrong way. If a button was currently focussed it displayed the disabled icon. I had messed up the different button states and too many states got the disabled icon.