Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Can we remove Dialog or Mainwindow written on the top of Application output.



  • @J-Hilk

    I think my fellow poster's may lead you in the wrong direction.

    Nah, I don't think so. The OP wrote:

    Can we remove the dialog/Black menu line written on the top of the output screen
    Yes i have taken dialog box without buttons and i want o remove that dialog caption and that black line

    I think the "black line" does mean he wants the whole of the dialog title (including the button furniture at top-left, whether he has realized that or not) removed, not just the title string itself.

    So he needs to try dialog->setWindowFlag(Qt::FramelessWindowHint, true);, or this->setWindowFlag(Qt::FramelessWindowHint, true); if he is inside QDialog-derived code.


  • Moderators

    @JonB oh,
    I only read the title of this thread ...

    Can we remove Dialog or Mainwindow written on the top of Application output.



  • @J-Hilk Always pays to read the body of threads too ;-)



  • @jsulm

    Yeah tried but its throwing below mentioned error

    /home/ashutosh/Ashu_QT/Main_Demo/menu.cpp:10: error: 'setWindowFlag' was not declared in this scope
    setWindowFlag(Qt::FramelessWindowHint,true);

    //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    i have tried with this "setWindowFlags(Qt::FramelessWindowHint);" as well and thus function is closing the whole window.


  • Lifetime Qt Champion

    @Ashutosh_Sachdeva Please show your code, I do not want to guess...



  • @JonB

    Sorry, may be i'm doing something wrong but i'm not able to find anyfunction named "Setwindoflag" (this can be stupid but i don't know why this is happening) . And i'f i'm using "setwindowflags" this function is closing the complete page.



  • This post is deleted!

  • Lifetime Qt Champion

    @Ashutosh_Sachdeva said in Can we remove Dialog or Mainwindow written on the top of Application output.:

    And i'f i'm using "setwindowflags" this function is closing the complete page

    If using setWindowFlags you need to keep all other flags:

    setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
    


  • @Ashutosh_Sachdeva said in Can we remove Dialog or Mainwindow written on the top of Application output.:

    @JonB
    Sorry, may be i'm doing something wrong but i'm not able to find anyfunction named "Setwindoflag" (this can be stupid but i don't know why this is happening) . And i'f i'm using "setwindowflags" this function is closing the complete page.

    At no point do I see Setwindoflag [sic.] written by any of us, so why do you write that? Did you search in the documentation for setWindowFlag, where you would have come across https://doc.qt.io/qt-5/qwidget.html#setWindowFlag? Not too hard to find. I have no idea what you mean by "And i'f i'm using "setwindowflags" this function is closing the complete page.", but never mind.

    In your code I see:

    //setWindowFlags(Qt::FramelessWindowHint);
    this->setWindowFlags(Qt::FramelessWindowHint,true);

    I don't think the second line should even compile.

    You have a class named Menu which derives from QDialog. This is not a helpful name, especially since Qt has a QMenu which is what I initially thought your code would be about. You might like to think about renaming that.

    You have pasted hundreds of lines of your code when all you are asking is how to suppress the dialog's title bar.

    You need to try exactly what we have been saying. In place of your own attempts at the start of Menu::Menu(), have you tried:

    setWindowFlag(Qt::FramelessWindowHint, true);
    

    If you have, and it gives

    error: 'setWindowFlag' was not declared in this scope
    

    then I would guess you are on a Qt version prior to 5.9? In which case (apart from why not a later one?) it would really help if you said so! As you can see from the doc page, setWindowFlag() was introduced in Qt 5.9. If you are earlier try instead:

    setWindowFlags(windowFlags() | Qt::FramelessWindowHint);
    

    Please use copy & paste to ensure you get this as written.

    At that point, does it indeed compile and get rid of the dialog's title bar, as I believe you were asking for?

    I have had my grump in this reply :) I hope the above does work for you.



  • @jsulm
    Thanku So much Sir. setWindowFlags(windowFlags() | Qt::FramelessWindowHint); working fine.



  • @mrjj @jsulm Thanku so much guys for spearing your time and helping. You guys are helping a me lot in learning QT.



  • @jsulm Hi,

    I have one more doubt here as now i have deleted that main-window title and menu bar so if now i want to come back to my previous page then what will be the method to close current page and go back to previous



  • Ah well, @mrjj & @jsulm get all the thanks, even when quoting the code I typed into my reply for pre-5.9 which is what the OP needed for his solution (edit whoops, bad hair day :) ). Perhaps I shouldn't have typed in all the stuff it took me time to do....



  • @JonB
    Hello Sir,

    Thanku so much and i really appreciate that u have speared your precious time to help and it really helpful for me and as a beginner i have a lot of thing to learn from you guys. And also looking forward for more help from you. And sorry that i missed the stuff some how as i saw the top reply and it solved the problem too.

    Thanku once again for the help and looking toward to learn more from you.



  • @Ashutosh_Sachdeva
    Sorry, you are right. I now see @jsulm posted

    If using setWindowFlags you need to keep all other flags:

    setWindowFlags(windowFlags() | Qt::FramelessWindowHint);

    I truly never spotted that he had offered that! My bad! I get tetchy... ;-)



  • @JonB
    I have one more doubt here as now i have deleted that main-window title and menu bar so if now i want to come back to my previous page then what will be the method to close current page and go back to previous.

    as this->hide will hide the previous page but i want to store the status of current page as if i want to go back i can go back to previous page or my main menu page.

    I hope i'm able to explain my requirement



  • @Ashutosh_Sachdeva
    Deleting title bars does not affect anything.

    While you are dealing with (modal) dialogs the "going back" does not apply, you don't leave the calling page.

    If you have separate windows somewhere, and you want to display one at a time and navigate between them, use QStackedWidget. This will preserve state, and you won't be using hide/show yourself. (Having said that, it will use hide/show internally, using those on windows/widgets does not lose state.)



  • @JonB

    OK, But what i'm asking for ex. i have one menu page and there is one drop down menu, now if i click on one of the item from menu it will take me to that page and now if i want to back to menu page then how can i go as now we have a window without any cross button on the left corner to close the window.

    "for ex. i saw somewhere if we click right button of the mouse then current page will be closed and it will take us to main menu page back and so on."



  • @Ashutosh_Sachdeva

    • I don't understand your "menus" sometimes a menu seems to mean a dialog and sometimes it seems to mean some dropdown menu. Which is why I said you might wish to change your terminology, for precisely this reason.

    • As I said, if your "menu" is a "modal dialog" which you call exec() on, afterward you will be back in the calling page.

    • Yes, if you choose to remove the title bar on a window/dialog which has the close button then you won't have a close button to press, as I mentioned earlier. You will have to provide some other means (button, key press, right-click, whatever you invent) to exit the dialog/window. Or, for a stacked widget, you would typically have links down the lefthand side to allow navigation between pages. I don't know what else to say.

    "for ex. i saw somewhere if we click right button of the mouse then current page will be closed and it will take us to main menu page back and so on."

    You would have to implement that yourself, it doesn't come "out-of-the-box".

    If you really want more help on this, I suggest you clarify what you mean, because reading a post which talks about a "menu" being both a "dropdown" and a "page" makes it impossible (for me) to understand.



  • @JonB
    Ok i will try to be more specific from next time.

    Now i have created a mouse event to close the current window. But now what where i got stuck is:

    Suppose you have three pages from first page you triigered to second page and from second page you triggered to third page and now you want to come back to second page from the third page. So how can you hide/close the current page only

    void Searchpage::mousePressEvent(QMouseEvent *event)
    {
    if(event->buttons()== Qt::RightButton)
    {
    hide();
    }
    }

    if i'm using the hide function its's hiding the all other pages.



  • @Ashutosh_Sachdeva
    I don't know, you're presumably hiding the wrong page, or you need to reshow the second page (secondPage->show()), or whatever is necessary.

    Did you look at QStackedWidget? If you can use that it will be better than your potentially-ugly-and-complex list of hides & shows.



  • @JonB

    Yes i have gone through the QStackWidget.

    And mouse event function is also working fine now .



  • @Ashutosh_Sachdeva
    Assuming you mean you have changed over to QStackedWidget, isn't it nicer/cleaner than all those show/hides yourself? And it makes code easier to follow. :)


Log in to reply