[Solved]How can I launch a QWizardPage with a key?



  • @kshegunov Ohh I see!!! Ok ok now I understand what it is doing and that yes, I had to create a file (.ui in my case). I've see also in the Qt Designer view that the buttons Ok and Cancel are inside a buttonBox called... buttonBox xD so ofc I can't do QObject::connect(ui.okButton, SIGNAL(clicked()), &dialog, SLOT(accept())); But I can QObject::connect(ui.buttonBox, SIGNAL(clicked()), &dialog, SLOT(accept())); but don't know how to access those buttons.. should I do only one connect with the buttonBox and then in the SLOT try to know which button was pressed??

    And I have another question, what are those connect exactly for? In my case I can just:

    Ui::Dialog ui;
    ui.setupUi(&dialog); 
    int result = dialog.exec(); 
    if (result == QDialog::Accepted)    
             close();
    

    Right?
    And yes, it helped a lot! :D


  • Qt Champions 2017

    @roseicollis said:

    But I can QObject::connect(ui.buttonBox, SIGNAL(clicked()), &dialog, SLOT(accept())); but don't know how to access those buttons.. should I do only one connect with the buttonBox and then in the SLOT try to know which button was pressed??

    Nope, your buttons have names too, so access them by their name:

    Ui::Dialog ui;
    ui.buttonNameHere; //< This is the button with name "buttonNameHere"
    

    And I have another question, what are those connect exactly for? In my case I can just:
    ...
    Right?

    Nope, QDialog::exec() will block until the dialog is closed. So the connects are there to ensure that clicking on the button will close the dialog with the appropriate status, either Accepted, set by the accept() slot, or Rejected, set by the reject() slot.



  • @kshegunov said:

    Nope, your buttons have names too, so access them by their name:

    Yes i know every widget has a name but as those buttons were created by Qt when I created the ui, I see them in a buttonBox and i don't see their names separately ( I can do ui.buttonBox->Ok for example but not sure if its the Ok button) and even being able to do that, I can't put ui.buttonBox->Ok on the connect.

    Well if I press Enter on the Ok button it closes all so it seems it works correctly and closes everything, I don't see the difference with or without connects... :S


  • Qt Champions 2017

    @roseicollis
    Honestly, I have no idea how the button box works. I have never used it myself. If I had to guess it directly connects to the dialog in its constructor, but I have to check the source to be sure. You could access its button with QDialogButtonBox::button if you need.

    Edit:
    Indeed the button box will connect the buttons to an internal handler, which in turn handles the actions and emit the signals. Or not, in any case it doesn't really matter why it works, only that it works. :D

    Kind regards.



  • @kshegunov I'm freaking out... I had 3 ways of getting what I wanted: 2 with QMessageBox and one with QDialog and all them worked fine on the pc... the QMessageBox had the title bar even if I put the flag to avoid it but decided it was not important if it appears...

    Today I wanted to test the program in the HW where it goes and found that the title bar wasnt there (which is cool) BUT... When the dialog/message appears, there is no focus on the Yes/Cancel buttons as you have them in the Pc (And also the borders and more things are missing). My mate told me that as the HW has been limited it's so possible that there are some dlls missed and they don't want to put them so my problem now is... how can I access those buttons to make them have the focus (in QDialog. in QMessageBox i'm looking how the buttonbox works )? I've tried some things but nothing appears to work...



  • Add more info:

    I've tried to not put the default buttons and put mines in a QMessageBox.
    They appear correctly but again, in pc they have the focus but in the HW they don't (And I can see behind the message a QPushButton from the WP focused.. dunno if this is the problem that there can be only 1 focus, or if they are 2 different focus (one for the wp and another for the messagebox))

     QMessageBox box(
                QMessageBox::Warning, //< Icon
                QString::fromUtf8("Confirm"),
                QString::fromUtf8("Really want to quit?"),
                QMessageBox::NoButton ,
                NULL, //< or this <-- dunno what that does
                Qt::Dialog | Qt::CustomizeWindowHint //< yeah! no title bar on the HW while I can see it in the pc... what a troll..
            );
    
            QPushButton *yesButton = box.addButton(tr("Yes"), QMessageBox::YesRole);
            QPushButton *noButton = box.addButton(tr("No"), QMessageBox::NoRole);
            yesButton->setFocus();
    

  • Qt Champions 2017

    @roseicollis
    Hello,

    I'm freaking out...

    From my experience this is also very Spanish of you ... ;) Take a breath, there's nothing to freak about.

    My mate told me that as the HW has been limited it's so possible that there are some dlls missed and they don't want to put them

    Nope, when you don't put a parent for the dialog (or any widget for that matter) it is created as a native widget. This means that the window styles, decorations and such are managed by the window manager. The window manager can choose to ignore the flags you pass it, so there are really no guarantees. Putting a parent to the dialog/widget, thus Qt creating it as alien widget, have other implications though so I think it'd be best to stick to dialogs that have no parent.

    I've tried to not put the default buttons and put mines in a QMessageBox.

    No need to do that for "Yes/No" buttons, as this is already provided to you by the message box.

    dunno if this is the problem that there can be only 1 focus, or if they are 2 different focus (one for the wp and another for the messagebox))

    As far as I know you can have only one widget focused. In any case I don't think the focus is the problem. I think it might be that on your (other) HW the default button is not set properly.
    So to your code snippet:

    QMessageBox box(
        QMessageBox::Warning,
        QString::fromUtf8("Confirm"),
        QString::fromUtf8("Really want to quit?"),
        QMessageBox::Yes | QMessageBox::No, //< Leave those in peace, no need to change them.
        NULL, //< This is the dialog's parent widget, NULL for no parent
        Qt::Dialog | Qt::CustomizeWindowHint //< Depends on the window manager's mood!
    );
    
    QPushButton * yesButton = qobject_cast<QPushButton *>(box.button(QMessageBox::Yes)); //< Get the "Yes" button
    
    Q_ASSERT(yesButton);  //< Only ensures that yesButton is not NULL, not that it should be.
    yesButton->setDefault(true);  //< Set the "Yes" button to be the default for the dialog.
    

    What applies to the message box, also applies to any dialog. You can get your buttons in a similar fashion (look up the docs as I'm lazy-ish) - there's a function get the buttons from a button box. It's done exactly as I've shown here for the QMessageBox.

    Try what happens if you set the default button manually, and let me know.

    Kind regards.



  • @kshegunov said:

    From my experience this is also very Spanish of you ... ;)

    haha yeah, I had to use google translate to find something to say " I can't believe what is happening now..." do you know the english expression? :D

    QMessageBox::Yes | QMessageBox::No, //< Leave those in peace, no need to change them.

    Are you sure you want to leave them alone? They seem suspicious... hahaha sorry that comment make me laugh.. couldn't resist to make a joke :P

    Your code snippet works as all the before test.... Its really pretty with its warning icon... the message... no title bar... and its f**** buttons not focused or able to focus hahahaha

    EDIT:

    QPushButton * yesButton = qobject_cast<QPushButton *>(box.button(QMessageBox::Yes)); //< Get the "Yes" button

    Oh! Thank you for showing me how to get its Yes button! I'm not used to do that cast things so I never think about them (And honestly I don't know so well how to use it yet)



  • @kshegunov said:

    As far as I know you can have only one widget focused. In any case I don't think the focus is the problem. I think it might be that on your (other) HW the default button is not set properly.

    Sorry for the second post but I think its necessary (And as I see you online I dont want to cross again with your answer...
    I've look about that you said... in the pc I have the focus in WP1's first QPushbutton (lets call it PB1) for example, then I press Esc and the QMessageBox appears having the focus itselft and its yes button and I can see the PB1 not focused anymore....
    Nevertheless when I do it in the HW, as I said, I'm in WP1 with PB1 focused, then press Esc and the QMessageBox appears but it does not have a focus, neither its buttons and I can see the focus on PB1 (But can't move or do anything with TAB as it should if I where in WP1)... dunno if i explain it well.. if it is not clear please let me know. Ty!


  • Qt Champions 2017

    @roseicollis

    do you know the english expression?

    As far as I can tell, the one you quoted is a perfectly valid English expression.

    Nevertheless when I do it in the HW, as I said, I'm in WP1 with PB1 focused, then press Esc and the QMessageBox appears but it does not have a focus, neither its buttons and I can see the focus on PB1 (But can't move or do anything with TAB as it should if I where in WP1)... dunno if i explain it well.. if it is not clear please let me know.

    This is very strange. I don't know what's happening or why the focus is not transferred to the message box. It sounds silly, but did you update your HW program with the last one (with the last code)? Also you could try setting a parent to the message box (substitute NULL for this in the constructor) and see if that works better (it won't be able to leave the main window area, but hopefully this won't be a problem). You could try also to set all the default properties that the button should have (although this doesn't seem like a good approach, but if it works ...):

    yesButton->setFocus(Qt::OtherFocusReason);
    yesButton->setAutoDefault(true);
    yesButton->setDefault(true);
    

    Additional note (not related to the focus):
    Don't use QString::fromUtf8 like you're doing, what you had before (tr("some text")) was perfectly fine.

    Kind regards.



  • @kshegunov said:

    As far as I can tell, the one you quoted is a perfectly valid English expression.

    Ok.. as you said it was something spanish I thought that thas a bad-literal translation...

    It sounds silly, but did you update your HW program with the last one (with the last code)?

    Yes it might seem silly but it isn't.. so many problems came from here but in this case it is silly because as I've got a lot of problems (releases that doesn't update well.. and so on), what I do every time is deleting the old release and then generate the new one and also I always check the date and time of the file...

    I forgot to add on my last post that I also tried with that:

    yesButton->setFocus();
    yesButton->setFocusPolicy(Qt::TabFocus);
    

    And I've tried with your last lines and still its the same... the focus is stuck in the PB1... u.u'' I'm trying everything I think but nothing.... what a problem (I ran out of time and all those little gnomes/mushrooms/code strange problems doesn't help me so much) xD

    Don't use QString::fromUtf8 like you're doing, what you had before (tr("some text")) was perfectly fine.

    Which is the difference between "text" and tr("text") ? In my case I have to use QString::fromUtf8 because its the only way I can use accents in my text and ofc my app is in spanish... I just switch it to english to post it here so it will be more understandable to everyone who reads this topic :) So my code its something like QString::fromUtf8("ConfirmaciĆ³n");

    Kind regards for you too!! :D hehe


  • Qt Champions 2017

    @roseicollis

    Also you could try setting a parent to the message box (substitute NULL for this in the constructor) and see if that works better (it won't be able to leave the main window area, but hopefully this won't be a problem).

    What about this? I'm really running out, or more correctly have run out, of ideas ...

    Which is the difference between "text" and tr("text") ?

    "text" is of type const char * const - a string literal, while tr("text") takes the string "text" and looks it up into the translation tables to create a QString from it that's translated to the currently set language. However, your next explanation seems like a valid reason to use QString::fromUtf8 instead, since you don't appear to be using the translation framework.

    Kind regards.



  • @kshegunov said:

    try setting a parent to the message box

    Sorry didn't saw it. Tried and its the same, the only thing that changes is that, as the default text is red in the parent, the QMessageBox's text is red too. but still the samebehaviour with PB1 focused... the QMessage appears like if you put a stick there....

    I'm really running out, or more correctly have run out, of ideas ...

    Wow! I thought that would never be possible!! :D Haha you had a lot of different ideas :D My next thought is: how could I do this confirm message without using QMessagebox or QDialog (I still dunno why do you call it "modal").. I'm trying to think how to do it if those classes didn't exist.. but not sure about the options...

    "text" is of type const char * const - a string literal, while tr("text") takes the string "text" and looks it up into the translation tables to create a QString from it that's translated to the currently set language.

    I think I understand you but do you know any clear example? I think that you mean that if it has to change any letter it will o it but not sure

    However, your next explanation seems like a valid reason to use QString::fromUtf8 instead, since you don't appear to be using the translation framework.

    Are you sure? Oh wow I did something fine! hahahaha (I'm trying to be positive xd)

    Note: I've tried also with:

    box.setFocus();
    box.setFocusPolicy(Qt::PopupFocusReason);
    

    ofc nothing works...


  • Qt Champions 2017

    @roseicollis

    My next thought is: how could I do this confirm message without using QMessagebox or QDialog (I still dunno why do you call it "modal").. I'm trying to think how to do it if those classes didn't exist.. but not sure about the options...

    Because they are modal, i.e. they don't allow the user to interact with other windows from your application. Modeless dialogs on the other hand can lose the focus and the user can interact with other widgets.

    On your second question:
    You could use a generic widget, however I really doubt that anything will change. Something like this:

    QWidget * dialogWidget = new QWidget(this);
    dialogWidget->setAttribute(Qt::WA_DeleteOnClose, true);  //< Takes care to delete the widget when it's closed.
    dialogWidget->setWindowModality(Qt::WindowModal);      //< Makes the widget modal
    
    // Initialize with a form:
    Ui::MessageFormUi dwUi;
    dwUi.setupUi(dialogWidget);
    
    // Connect buttons as appropriate here ...
    
    // And finally, show the widget
    dialogWidget->show();
    

    I think I understand you but do you know any clear example? I think that you mean that if it has to change any letter it will o it but not sure

    No I don't have an example on hand, you could try the translation framework's documentation, it should be explained there.

    Kind regards.



  • @kshegunov I've see something curious...maybe it helps or enlight someone... As I said the program is going to run only with keyboard but I can connect a mouse on my tests so I did it to see what happened. If I mouseover the Yes/No buttons they get the focus and if I click on them they do what they have to do....

    What I can't understand is why:

    • in the Pc you see: the program normal > press Esc > then it appears more obscured like with fog so you see clearly the QMessageBox and center your vision on it and the focus dissapears from PB1 to the Yes button
    • in the HW: the program normal > press Esc> then ... it appears as a moment before, with the PB1 focused, not obscured, no changes... but with the QMessageBox in the middle like a stick and like if the program where frozen (but it isn't as I can use mouse and click on Yes/no buttons).

    I'll try now your example with a widget and tell you something as soon as possible :)

    No I don't have an example on hand, you could try the translation framework's documentation, it should be explained there.

    Ok don't worry I'll search it later :D

    Thank you!

    EDIT:

    1. My mate told me that there is no window manager in the HW (this is one of the dlls they took off....) so maybe this is the problem.. but I still have to find a solution to my problem...
      I've tried using box.grabKeyboard(); with QMessageBox and guess what? Still the same behaviour .. BUT if you press Y (of Yes) it closes the program and if you press N (of No) it closes the QMessageBox... Its something but its really ugly and not a final solution as there is no focus on the buttons and the users can't guess that (Even if I write something as: Do you want to quit? Press Y if yes, N if don't"

    2. About your widget solution... I must be missing something because it does not show up.... I did add new>qt form>QWidget>named it MessageFormUi.ui >runqmake> added #include "ui_MessageFormUi.h" but then I can't use the Ui::MessageFormUi *ui; I had to use Ui::Form *ui ... I couldn0t use MessageFormUi... I copy the code snippet.. its just the same as yours but it doesn't show up (connections will come later if it is shown on screen)

            QWidget * dialogWidget = new QWidget(this);
            dialogWidget->setAttribute(Qt::WA_DeleteOnClose, true);  //< Takes care to delete the widget when it's closed.
            dialogWidget->setWindowModality(Qt::WindowModal);      //< Makes the widget modal
    
            // Initialize with a form:
            Ui::Form dwUi;
            dwUi.setupUi(dialogWidget);
    
            // Connect buttons as appropriate here ...
    
            dialogWidget->show();
    

    Thanks and regads!


  • Lifetime Qt Champion

    You should use a QDialog if you expect your widget to act as dialog.



  • @SGaist said:

    You should use a QDialog if you expect your widget to act as dialog.

    Hi Sgaist, thanks for your reply. I tried it too with the next code:

    QDialog dialog(this, Qt::Dialog | Qt::CustomizeWindowHint);
    Ui::Dialog ui;
    ui.setupUi(&dialog);
    int result = dialog.exec();
    if (result == QDialog::Accepted)
        close();
    

    And it shows up BUT I'm still having the same problem... in the HW the focus is not passed from WP to this dialog and I can't focus the Yes/No buttons...


  • Qt Champions 2017

    @roseicollis

    My mate told me that there is no window manager in the HW

    I'm really doubtful of this, I believe your mate is feeding you misinformation.

    but I still have to find a solution to my problem...

    It might be impossible.

    About your widget solution... I must be missing something because it does not show up....

    Or possible I've missed something, as I'd never tried that. Honestly, I've never heard of such problem as yours with the dialogs, and have never experienced something similar myself.

    Unfortunately, I have nothing further to suggest.

    Kind regards.



  • @kshegunov Well.. we have decided to use the dialog and tell the user to press Y or N to exit or not and this issue about the focus will be a future bug to fix... (hope this 'future time' never cames... ) XD

    Thank you so much for ALL your help and patience ^^ @kshegunov and @SGaist Really grateful :D

    I'll try to solve the other problems (posted in this forum too) about going back 2 pages and the key buffer issue :)


  • Qt Champions 2017

    @roseicollis

    Well.. we have decided to use the dialog and tell the user to press Y or N to exit or not and this issue about the focus will be a future bug to fix

    I think this a practical decision.

    Thank you so much for ALL your help

    Anytime. Take care!

    Kind regards.