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



  • Hi!

    I'm working on Qt 4.8.5 and doing a QWizard program with its QWizardPages.... I want to launch a especific QWizardPage if user press a key. That means:

    No matter where user is, he can press Esc where I quit the application:

    bool BasePage::eventFilter(QObject *obj, QEvent *event)
    {
        if(event->type() == QEvent::KeyPress)
        {
            QKeyEvent *key = static_cast<QKeyEvent *>(event);
    
           if (key->key() == Qt::Key_Escape)
            {
                QApplication::quit();
            }
            ....
        }
    }
    

    Now what I want is to launch a especific QWizard page (let's call it ConfirmEsc) so I can ask the user if he really wants to quit or not. I want to do it with a QWizardPage to be able to have the same style than the other pages.

    Any idea of how can I achieve this? Thank you!


  • Qt Champions 2016

    @roseicollis
    Hello,

    Now what I want is to launch a especific QWizard page (let's call it ConfirmEsc) so I can ask the user if he really wants to quit or not. I want to do it with a QWizardPage to be able to have the same style than the other pages.

    Use a modal dialog and style it up the same way. Such input solicitation windows are not wizard pages, so you shouldn't use QWizardPage for them.

    Kind regards.



  • Well... the problem is that this app is used only with a keyboard, no mouse allowed, and it has to have big buttons so I wanted to call a QWizardPage to ask if they want to quit or not and the user has to select a QPushButton bigger than the QWizard own buttons (Back, next...)


  • Qt Champions 2016

    @roseicollis

    Well... the problem is that this app is used only with a keyboard, no mouse allowed, and it has to have big buttons so I wanted to call a QWizardPage to ask if they want to quit or not and the user has to select a QPushButton bigger than the QWizard own buttons (Back, next...)

    Notwithstanding that, you still should use a modal dialog and not a wizard page.


  • Lifetime Qt Champion

    Hi,

    I agree with @kshegunov on that point. Use a dialog for that task, the user can then either change the focus of the button using tab or use escape to dismiss the dialog.



  • Ok I'll try it and if I have a problem I'll tell you...I supposse I can do that dialog as big as I want and so his buttons?


  • Lifetime Qt Champion

    If you make the dialog modal then there's no risk that the user does something else with the application.



  • @SGaist @kshegunov I'm trying to do it with:

        QDialog *a = new QDialog(this,Qt::WindowTitleHint);
        a->setModal(true);
        a->show();
    

    And it appears (bigger as expected but I'll see later how to change it) My problem is that this program is used only with a keyboard so no mouse allowed so I don't want the tittle bar or at least I don't want the minimize/maximize/close buttons that appear upside right... how can I hide it?

    Another question which is the difference between a message box and a modal dialog? Does message box have only the Ok button?

    I just need a little window where it says something like" are you sure you want to exit?" and the buttons: Yes and No.


  • Qt Champions 2016

    @roseicollis
    Hello,
    Consider the following example where some flags are passed to the dialog constructor.

    // (Un)set some window flags for the dialog
    QDialog dialog(this, (Qt::Dialog | Qt::CustomizeWindowHint) & ~(Qt::WindowTitleHint | Qt::WindowSystemMenuHint | Qt::WindowMinMaxButtonsHint | Qt::WindowCloseButtonHint | Qt::WindowContextHelpButtonHint));
    int result = dialog.exec();  //< Use QDialog::exec for modal dialogs
    

    Of course one could notice that this should also work, unless the flags' values are changed at some point:

    QDialog dialog(this, Qt::Dialog | Qt::CustomizeWindowHint);
    dialog.exec();
    

    EDIT:
    I missed your second question. Yes, you can use a message box, as it's a dialog itself.

    I just need a little window where it says something like" are you sure you want to exit?" and the buttons: Yes and No.

    For this I'd usually use a QMessageBox, however I haven't checked if the system menu and title bar can be disabled, but I see no reason why it shouldn't be possible.

    Kind regards.



  • @kshegunov said:

    QDialog dialog(this, Qt::Dialog | Qt::CustomizeWindowHint);

    Oh.. I saw those flags but tried with one and made my dialog not appear so thought it was a bad idea, but I was doing it wrong.

    I don't know if its because of the big cold I have or what but I can't see how to add QWidgets to that dialog (a label and the 2 buttons). Should I make my own dialog class ( class MyDialog : public QDialog) or is there an easy way? I douln't find how to do it even in google... o.o

    //----------------
    I've found another solution with the QMessageBox:

            QMessageBox::StandardButton dialog;
    
            dialog = QMessageBox::warning(this, "Confirm",  "<font color=\"#000\">Do you really want to quit?</font>",  QMessageBox::Ok | QMessageBox::Cancel); // by default my colour is red so I had to force it to black here with css
            if( dialog == QMessageBox::Ok) 
                close();
            else 
                event->ignore();
    

    But... I can't see how can I take off the title bar in this case, or how can I set some stylesheet for the background of that message bos (I usually do somethink like dialog->setStyleSheet("background-color: #fb0;");).

    So tried with the next code which allows me to change the background color but can't get rid of the title bar and can't find how to close the program with its Ok button :

    QMessageBox msgBox(tr("Title"),
            tr("Do you really want to quit the application?"),
            QMessageBox::Warning,
            QMessageBox::Ok,
            QMessageBox::Cancel,
            QMessageBox::Escape);
            msgBox.setStyleSheet("background-color: #AAA;");
            msgBox.exec();
    

    And also I want to know how to reach that with the modal dialog to learn that way to do it...


  • Qt Champions 2016

    @roseicollis

    Hello,

    Oh.. I saw those flags but tried with one and made my dialog not appear so thought it was a bad idea, but I was doing it wrong.
    I don't know if its because of the big cold I have or what but I can't see how to add QWidgets to that dialog (a label and the 2 buttons). Should I make my own dialog class ( class MyDialog : public QDialog) or is there an easy way?

    Deriving from QDialog is one option, yes. I personally tend not to do it though. I initialize the forms "from the outside" like this (which you could also use in this case):

    QDialog dialog(this, Qt::Dialog | Qt::CustomizeWindowHint);
    
    // Create the form and initialize the dialog with it.
    Ui::DialogForm ui;
    ui.setupUi(&dialog); //< Initialize the dialog with the form
    
    // Connect the buttons from the form ...
    QObject::connect(ui.okButton, SIGNAL(clicked()), &dialog, SLOT(accept()));
    QObject::connect(ui.cancelButton, SIGNAL(clicked()), &dialog, SLOT(reject()));
    
    // ... Fiddle with the dialog more (if needed), add stylesheet w/e
    
    // Display the dialog and handle the result
    int result = dialog.exec(); //< Display a modal dialog.
    if (result == QDialog::Accepted)  {   //< The dialog was accepted (ok button clicked)
        // ... Do more things based on that
    }
    

    You could do similar things with the QMessageBox, but then you shouldn't be displaying it with the static functions.
    I hope this helps to get you started.

    Kind regards.


  • Qt Champions 2016

    @roseicollis
    Hello,
    If you edit up your post after I've posted, I won't get a notification and will never know something has changed. I stumbled upon the changes by pure luck, so if you'd forgotten something or wish to explain more, please post it separately.

    Now, your message box code is wrong, that's why it's not working. Something like this should suffice:

    QMessageBox box(
        QMessageBox::Warning, //< Icon
        tr("Title"),
        tr("Do you really want to quit the application?"), 
        QMessageBox::Yes | QMessageBox::No, //< Buttons
        NULL, //< or this 
        Qt::Dialog | Qt::CustomizeWindowHint //< Window flags
    );
    
    box.setStyleSheet("");  // You can still set a stylesheet here if you wish
    
    int result = box.exec();
    if (result == QMessageBox::Yes)  {  //< Well, the user clicked yes, so do stuff
    }
    

    The Qt documentation provides a pretty fine set of examples on message boxes. I don't know what QMessageBox::Escape is, probably you got it confused from the roles the buttons can have, however for a yes/no message box, these aren't needed.

    Kind regards.



  • @kshegunov First of all sorry. I didn't meant to edit the post but came after lunch and saw that I forgot to press the Submit message so I did it thinking you didn't saw the last message. I'm so sorry for that. Thanks for seeing it but if you look at it I just added more things I've tried :)

    I always look on the Qt documentation but sometimes I miss some info or dunno really how to do it. I was looking for dialog instead of QMessageBox so I didn't the link you have posted, thanks!

    Now with your QMessageBox box example I understand clearly how it works.

    What I don't get is the modal dialog example where you say

    // Create the form and initialize the dialog with it.
    Ui::DialogForm ui;
    ui.setupUi(&dialog); //< Initialize the dialog with the form

    I'm creating that "message" in the ::keyPressEvent() of my QWizard class ( class MyWizard: public QWizard) so... writting your code as is, it says:
    error: 'DialogForm' is not a member of 'Ui'
    I've tried creating it in the .h:

    private:
        Ui::DialogForm *ui;
    

    And then in the constructor:

    MyWizard::MyWizard(QWidget *parent) :
        QWizard(parent),
        ui(new Ui::DialogForm)
    {
    

    but then it complains with the .h line saying error: 'DialogForm' in namespace 'Ui' does not name a type and if I change the DialogForm for my MyWizard then of course says that can't convert dialog into QWizard in the line ui.setupUi(&dialog);

    What am I missing here¿?
    (I don't have the MyWizard default ui because I don't use it and I take it off... dunno if that has something in common with my problem)


  • Qt Champions 2016

    @roseicollis said:
    Hello,

    I didn't meant to edit the post but came after lunch and saw that I forgot to press the Submit message so I did it thinking you didn't saw the last message. I'm so sorry for that.

    No problem, it happens, I'm just suggesting to be sure before editing, so there won't be things missed in the confusion. Editing a typo, a missed word is still fine, as it doesn't change the meaning. :)

    I'm creating that "message" in the ::keyPressEvent() of my QWizard class ( class MyWizard: public QWizard) so... writting your code as is, it says:
    error: 'DialogForm' is not a member of 'Ui'

    This means your compiler is complaining, because there's no such class defined. Did you include the form header? Ordinarily when creating a class for a form, you make something like this:

    #include <QDialog>
    #include "ui_mydialogform.h"  //< This comes from the uic when your form is compiled
    
    class MyDialogForm : public QDialog
    {
        Q_OBJECT
    
    public:
        MyDialogForm(QWidget * parent = NULL)
            : QDialog(parent), ui(new Ui::MyDialogForm)
        {
            ui->setupUi(this);
        }
    
        // ... Other things for the dialog ...
    
    private:
        Ui::MyDialogForm * ui;
    };
    

    correct?
    In my example, you don't create a separate class, so you'd have to do what the constructor would have done somewhere, you'd have something like this (in the source where you're using the dialog):

    #include "ui_mydialogform.h" //< This comes from the uic when your form is compiled
    
    // ... Some MyWizard functions ...
    
    void MyWizard::keyPressEvent(QKeyPressEvent * event)
    {
        QDialog dialog;
        Ui::MyDialogForm dialogUi;
        dialogUi.setupUi(&dialog);
        
        // Do things with the dialog and the dialogUi object ...
    }
    

    What am I missing here¿?

    Very Spanish of you to ask it like that. :D

    Here is described the direct approach, which I use, while you're used to doing it like in the single inheritance approach. A difference of methods, that's all.

    Kind regards.



  • @kshegunov said:

    Very Spanish of you to ask it like that. :D

    Hahahaha :P Yeah! how did you know that ? (I've jsut upload my profile info to show my country :D) Sorry for my bad english :(

    In my example, you don't create a separate class,

    With that I understand that you don't do another class so no .cpp or .h or .ui added to create that dialog but then you say that I have to:

    #include "ui_mydialogform.h" //< This comes from the uic when your form is compiled

    But I don't understand from where do you get it. As it is a .h then I understand that you are adding a .h file to the project (not a class because .cpp is not needed maybe) so I have to create this .h and include it, is it right? (If yes I understand that the .h content will be what you wrote up about class myDialogForm: public QDialog...) I'm a little bit confused...

    Thank you for all your help, and sorry for making this post so long but I want to learn things the best way (and not just copy-paste and forget how they work if they run as expected)


  • Qt Champions 2016

    @roseicollis said:

    Hahahaha :P Yeah! how did you know that ?

    The upside-down question mark is a dead giveaway.

    Sorry for my bad english :(

    Your English is just fine!

    With that I understand that you don't do another class so no .cpp or .h or .ui added to create that dialog but then you say that I have to:
    #include "ui_mydialogform.h" //< This comes from the uic when your form is compiled
    But I don't understand from where do you get it.

    When you add a form to your project (you have FORMS += someform.ui in the .pro file) qmake will run the user interface compiler (uic) on your .ui file and that produces the aforementioned header. It'll be named as the form is named with prefix ui_ and extension .h. So if you have someform.ui in your project, qmake will generate ui_someform.h for you.

    It's mentioned in passing (too casually for my taste to be honest) in the documentation:

    The special feature of this file is the FORMS declaration that tells qmake which files to process with uic. In this case, the calculatorform.ui file is used to create a ui_calculatorform.h file that can be used by any file listed in the SOURCES declaration.



  • @kshegunov said:

    The upside-down question mark is a dead giveaway.

    Ô.ó Right! hahaha Well seen!

    When you add a form to your project (you have FORMS += someform.ui in the .pro file) qmake will run the user interface compiler (uic) on your .ui file and that produces the aforementioned header. It'll be named as the form is named with prefix ui_ and extension .h. So if you have someform.ui in your project, qmake will generate ui_someform.h for you.

    I see.. interesting... but still lost :P (and while asking I'm trying things too, don't think I'm not just posting and waiting for an answer).

    What I had before posting here, was my MyWizard class where I want to add a dialog. And I understand that to use something like QDialog dialog; Ui::MyDialogForm dialogUi; I need to add a .h file but I don't get what should I do really.

    I've just tried adding a ui file with add new > form> dialog with buttons bottom>DialogForm.ui then I've run qmake and as you said I was able to add #include "ui_DialogForm.h" but then it complains in the Ui::DialogForm ui; and I have to change it to Ui::Dialog ui; but then ofc it complains with the next line saying that error: 'class Ui::Dialog' has no member named 'okButton' and the same with the cancelButton

    (I'm trying to understand the documentation link you show me meanwhile ^^)


  • Qt Champions 2016

    @roseicollis

    Ah, yes, that. The members are named after the object names provided in the designer. So if your root object is called Dialog then the class will be called Ui::Dialog as well. Here's a screenshot I've used in another thread.
    Designer

    I hope this helps.



  • @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 2016

    @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 2016

    @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 2016

    @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 2016

    @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 2016

    @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 2016

    @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 2016

    @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 2016

    @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.


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.