×

Discussion Board

Results 1 to 7 of 7
  1. #1
    Registered User
    Join Date
    Jun 2010
    Posts
    5

    Question help - positioning layout or widgets inside the layout

    Hi guys, this is my first post here asking for help after I saw and realized that this gonna be one-stop answers & solutions for my Qt projects. would be highly grateful and thanks for your advice in advance !

    This is what I am doing: mobile application using Qt and I use custom image background for main menu.
    This is what I want:

    ********************************************
    * Image Logo *
    * Image Logo *
    * Image Logo *
    * Image Logo *
    * *
    * link 1 *
    * link 2 *
    * link 3 *
    * link 4 *
    ********************************************

    So, I coded like this:
    Code:
        /******************* Custom Widget ********************/
        QWidget *mainPage = new QWidget;
        setCentralWidget(mainPage);
    
        /******************* Layout ***************************/
        QVBoxLayout *layout = new QVBoxLayout;
        layout->addWidget(link1);
        layout->setAlignment(link1,Qt::AlignHCenter);
        layout->addWidget(link2);
        layout->setAlignment(link2,Qt::AlignHCenter);
        layout->addWidget(link3);
        layout->setAlignment(link3,Qt::AlignHCenter);
        layout->addWidget(link4);
        layout->setAlignment(link4,Qt::AlignHCenter);
        mainPage->setLayout(layout);
    
        /******************* MainWindow***************************/
        setStyleSheet("QMainWindow { border-image: url(:/images/Default.png); }");
        setWindowTitle(tr("Tangram Tangram Tangram"));
    Base class is MainWindow and link1-4 are custom subclass of QPushButton because I want to add stylesheet + addition features such as background images and sounds.

    What actual outcome is that the layout overlaps the background image. I want to set the link buttons positions to lower: below the image logo and I tried setGeometry(Qrect) for both layout and links buttons, setSpacing() for the layout and nothing change.

    ********************************************
    * Image Logo *
    * link 1 logo *
    * Image Logo *
    * link 2 Logo *
    * *
    * link 3 *
    * *
    * link 4 *
    * *
    ********************************************

    When I googled for this problem, some people reimplement paintEvent(event) to position manually which obviously will be depending on the device you are targeting. For me, this is gonna be a tough task since I am quite new to Qt and Nokia Platforms.

    Can you suggest me what should I use for this ? Is there a built-in ready baked code which can set the layout or buttons position ? Links for any sample programs would be greatly appreciate

    Thanks in advance
    Last edited by mgph; 2010-08-03 at 16:06.

  2. #2
    Registered User
    Join Date
    Jun 2010
    Posts
    5

    Re: help - positioning layout or widgets inside the layout

    Can anyone suggest about manual positioning of widgets/buttons or layout ?

  3. #3
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: help - positioning layout or widgets inside the layout

    I'm inclined to just tell you to read http://doc.qt.nokia.com/4.6-snapshot/layout.html , but I'm in a generous mood today, so read http://doc.qt.nokia.com/4.6-snapshot...tml#addSpacing .

  4. #4
    Registered User
    Join Date
    Jun 2010
    Posts
    5

    Re: help - positioning layout or widgets inside the layout

    Quote Originally Posted by danhicksbyron View Post
    I'm inclined to just tell you to read http://doc.qt.nokia.com/4.6-snapshot/layout.html , but I'm in a generous mood today, so read http://doc.qt.nokia.com/4.6-snapshot...tml#addSpacing .
    Woah, I understand that I am supposed to read thoroughly the documentations and in fact I've read through again & again. Though the documents are so clear, all the methods I've tried with the help of documents(addSpacing,setMargin,paintEvent,...) didn't seem to work and that is WHY I'm here asking for help from people who have much more experience in Qt as well as software programming era. Maybe because of my stupidity or lack of experience with programming, I still cannot solve this GUI issue.

    Is pointing out the reference page and saying in a generous mood so much helpful uh ?! Sounds like a professor asking students to look at the things that the students are supposed to study before asking any questions. I know that people here are not getting paid for answering my questions but do NOT say you're in a generous mood and asking me to read the reference which looks like I am so lazy to read and instead just come here and ask for help hmm.

    Anyway, THANKS! and appreciate your time
    Last edited by mgph; 2010-08-04 at 04:11.

  5. #5
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: help - positioning layout or widgets inside the layout

    If addSpacing isn't doing it for you then there's something that you misunderstand that's shooting you in the foot. Step back a bit and study up on your basics.

  6. #6
    Registered User
    Join Date
    Jun 2010
    Posts
    5

    Re: help - positioning layout or widgets inside the layout

    Quote Originally Posted by danhicksbyron View Post
    If addSpacing isn't doing it for you then there's something that you misunderstand that's shooting you in the foot. Step back a bit and study up on your basics.
    I think it seems like I could solve it out by manually setting position for each button setGeometry(...) with the systeminfo functions to get the current device's size. But I think that my application will not be looked like the same on different devices' screens. Weird!

    thanks

    Sorry, I forgot to mention that I removed the QVBoxLayout to get GUI setup properly. Is it correct way to do ?

  7. #7
    Super Contributor
    Join Date
    Nov 2009
    Location
    Minnesota, USA
    Posts
    3,209

    Re: help - positioning layout or widgets inside the layout

    If you're going to do manual spacing you should remove the layout manager. But it should work with the layout manager and addSpacing -- you just had something wrong.

Similar Threads

  1. Getting layout
    By Kvet in forum Symbian
    Replies: 2
    Last Post: 2010-02-23, 07:47
  2. Detecting Keypad Layout and Screen Layout
    By chonada in forum Symbian User Interface
    Replies: 1
    Last Post: 2008-02-01, 03:13
  3. Fonts and LAyout
    By abrahim in forum Symbian User Interface
    Replies: 0
    Last Post: 2003-06-17, 13:10
  4. dialog layout
    By tolnaisz in forum Symbian
    Replies: 0
    Last Post: 2002-12-13, 12:29

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×