Advanced Search Bar



  • Hey there!
    So I have been making a browser and I have made a URL address bar, and a standard Google search bar. Although they work fine, I was hoping to improve them. I was wondering if there is a way to combine the code to make a Google Chrome-like 'Omnibar' where I can enter both the URL and a keyword. Here is the code to the urlbar and the search bar respectively:
    @void MainWindow::on_urlbar_returnPressed()
    {
    ui->webView->setUrl(ui->urlbar->text());
    }
    @

    @void MainWindow::on_searchbar_returnPressed()
    {
    ui->webView->setUrl(QUrl(QString("http://www.google.com/search?fs&q=")+(ui->searchbar->text())));
    }
    @
    I know the answer is probably super simple and I just don't see it. I was also wondering if there is a way to combine a progress bar and the urlbar kind of like Safari. Again, the answer is probably obvious. I was also wondering how to make 'special addresses' (for lack of a better term). For example I type '\Qt' into the urlbar and it takes me too this page, or '\fb' to go to Facebook, and so on. Thanks for all your help! This really is the best forum to get help on!



  • Oh, and before I forget, I was wondering if there is a way to color-code text within the urlbox kind of like firefox or chrome. The 'http://' header would be color A, the rest color B or something. Also is there a way to put buttons inside of the urlbox so I don't have to have the 'refresh' button on its own? (most major browsers do that). I know Im asking a lot of questions, and from the point of view of you master coders they must seem pretty dumb, but it would be great if I could get some help, even if on only 1 or 2 questions. Thanks!



  • Although they are probably stupid questions, some help would be appreciated!


  • Moderators

    [quote author="nicky j" date="1371005973"]
    I was wondering if there is a way to combine the code to make a Google Chrome-like ‘Omnibar’ where I can enter both the URL and a keyword.
    [/quote]

    if you type in "test" FF takes you to "https://www.google.at/search?q=test". This can be easily implemented by checking if the entered text starts with "http://" or maybe "www." ... if not open the google url.

    [quote author="nicky j" date="1371005973"]
    Again, the answer is probably obvious. I was also wondering how to make 'special addresses' (for lack of a better term). For example I type '\Qt' into the urlbar and it takes me too this page, or '\fb' to go to Facebook, and so on.
    [/quote]

    For just typing "Facebook" and getting redirected to www.facebook.com you can also let google do the work:
    http://www.google.at/search?q=<ENTERED-TEXT>&btnI=Im+Feeling+Lucky
    will open the best matching site it finds.

    [quote author="nicky j" date="1371005973"]
    I was also wondering if there is a way to combine a progress bar and the urlbar kind of like Safari.[/quote]

    This is not that trivial. You will have to subclass QLineEdit and override it's paintEvent. You will need to check out QLineEdit::paintEvent() implementation and copy some code there. Since you want a different (dynamic) background, which needs to be drawn before the text is drawn.
    Alternatively you can also play around with palettes and set a QLinearGradient with a "hard color break" at the position indicating the progress.
    e.g. gradient from green to white with the stops (for 45% progress):
    0: green
    0.45: green
    0.46: white
    1: white
    And set this gradient to the line edit's palette on every progress update:
    @
    QPalette pal = lineEdit->palette();
    //create gradient
    pal.setBrush( QPalette::Background, gradient );
    lineEdit->setPalette(pal);
    @

    But i haven't tested this though...

    [quote author="nicky j" date="1371005973"]
    Oh, and before I forget, I was wondering if there is a way to color-code text within the urlbox kind of like firefox or chrome. The ‘http://’ header would be color A, the rest color B or something.
    [/quote]
    For changing the color of some text parts in a line edit ther is some work involved but it can be done. Read "this":http://stackoverflow.com/a/14424003.

    [quote author="nicky j" date="1371005973"]
    Also is there a way to put buttons inside of the urlbox so I don’t have to have the ‘refresh’ button on its own? (most major browsers do that).
    [/quote]
    Just add the button as a child of the lineedit: Set the parent of the button to the lineedit. You will need to ensure that on every resize event of the line edit you do the repositioning of the button (e.g. with an event filter)



  • Hey!
    Thanks for the reply, it really helps!

    "if you type in “test” FF takes you to “https://www.google.at/search?q=test”. This can be easily implemented by checking if the entered text starts with “http://” or maybe “www.” … if not open the google url."
    .

    I have tried to implement this, but im not sure how. I believe I would need an 'if' statement, but I'm not sure how to make it check how the text starts. Could you give me some pointers?

    "This is not that trivial. You will have to subclass QLineEdit and override it’s paintEvent. You will need to check out QLineEdit::paintEvent() implementation and copy some code there. Since you want a different (dynamic) background, which needs to be drawn before the text is drawn.
    Alternatively you can also play around with palettes and set a QLinearGradient with a “hard color break” at the position indicating the progress.
    e.g. gradient from green to white with the stops (for 45% progress):
    0: green
    0.45: green
    0.46: white
    1: white
    And set this gradient to the line edit’s palette on every progress update:"

    I am not sure how to get the progress bar and the lineedit to occupy the same space. Im assuming I would somehow put the progress bar under the lineedit and adjust the lineedit's opacity. Im not sure how to get the progress bar under the lineedit though.

    Thanks again for your help!


Log in to reply
 

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