LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-21-2007, 10:35 AM   #1
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 444

Rep: Reputation: 30
Qt lining thing up properly


OK here's my code.
Code:
#ifndef PACKAGE_PROPERTIES_H
#define PACKAGE_PROPERTIES_H

#include <qvbox.h>
#include <qhbox.h>
#include <qlineedit.h>
#include <qcombobox.h>
#include <qfontmetrics.h>
#include <iostream>

class ComboInput
{
  QHBox* hb;
  QLineEdit* prompt;
  QComboBox* input;
public:
  ComboInput( QString p, QWidget *parent = 0, const char *n = 0 )
  {
    hb = new QHBox( parent, n);
    prompt = new QLineEdit( p, hb );
    prompt->setReadOnly( true );
    input = new QComboBox( hb );
  }

  int currentItem() {
    return input->currentItem();
  }

  void insertItem( QString s ) {
    input->insertItem(s);
  }

  int promptLength() const {
    QFontMetrics fm(prompt->font());
    return fm.boundingRect(prompt->text()).width();
  }

  void promptLength(int l) {
    prompt->setFixedWidth(l + 10);
  }
};

class LineInput
{
  QHBox* hb;
  QLineEdit* prompt;
  QLineEdit* input;
public:
  LineInput( QString p, QWidget *parent = 0, const char *n = 0) {
    hb = new QHBox( parent, n);
    prompt = new QLineEdit( p, hb );
    prompt->setReadOnly( true );
    input = new QLineEdit( hb );
  }

  QString text() const {
    return input->text();
  }

  int promptLength() const {
    QFontMetrics fm(prompt->font());
    return fm.boundingRect(prompt->text()).width();
  }

  void promptLength(int l) {
    prompt->setFixedWidth(l+10); //add ten pixels to allow for a border
  }
};

class PackageProperties : public QVBox
{
  LineInput* filename;
  LineInput* name;
  LineInput* version;
  ComboInput* arch;
  LineInput* build;
public:
  PackageProperties( QWidget *parent = 0, const char *n = 0 );
};

#endif
Code:
#include "PackageProperties.h"

PackageProperties::PackageProperties( QWidget *parent, const char *n) : QVBox(parent, n)
{
  filename = new LineInput( "File Name ", this );
  name = new LineInput( "Name ", this );
  version = new LineInput( "Version ", this );
  arch = new ComboInput( "Architecture ", this );
  arch->insertItem("i386");
  arch->insertItem("i486");
  arch->insertItem("i586");
  arch->insertItem("i686");
  arch->insertItem("noarch");
  build = new LineInput( "Build ", this );
  int len = arch->promptLength();

  //Set the prompt fields to one even length
  filename->promptLength(len);
  name->promptLength(len);
  version->promptLength(len);
  arch->promptLength(len);
  build->promptLength(len);
}
Now, the text box that says architecture doesn't line up with the rest of the other boxes. Is there a way I can make it line up? Also, do you have any design improvements or suggestions? I'm trying to learn how to program in linux and this is my first program, so please try not to be too harsh.
 
Old 11-22-2007, 09:27 AM   #2
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I think you're a lot better off using Designer to create your interface shells then connecting it to the back end manually. That way you focus on the true value of the interface and not the semantics of making it look like you want it to. I'm a hardcore "manual" coder myself, but even I think it's fairly primitive to manually code a GUI. It's just not natural
ta0kira
 
Old 11-22-2007, 11:09 AM   #3
Alien_Hominid
Senior Member
 
Registered: Oct 2005
Location: Lithuania
Distribution: Hybrid
Posts: 2,247

Rep: Reputation: 53
I probably would disagree. Debugging those created GUIs is annoying. But it is your choice.
 
Old 11-22-2007, 02:12 PM   #4
ta0kira
Senior Member
 
Registered: Sep 2004
Distribution: FreeBSD 9.1, Kubuntu 12.10
Posts: 3,078

Rep: Reputation: Disabled
I might have to counter-disagree. If you only use the designer (without an IDE) and put only enough code in the generated sources to connect the different components with each other and to the back end, I think that's a lot easier than trying to visualize the entire GUI based solely off of text code. I'd say writing a GUI by hand is more difficult to debug since the designer lets you assemble and preview a GUI in minutes.
ta0kira
 
Old 11-22-2007, 05:11 PM   #5
binarybob0001
Member
 
Registered: Dec 2004
Distribution: Debian Wheezy
Posts: 444

Original Poster
Rep: Reputation: 30
Thanks for the suggestions. I did manage to figure out how to make it line up correctly. First inherit from the QWidget class then define a minimum size hint.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
LXer: Lining up for Linux mobile LXer Syndicated Linux News 0 08-06-2006 11:12 PM
NEWB , cant seem to get this thing to shutdown properly adamf4i Mandriva 8 07-03-2006 02:06 PM
command lining in Mepis? jaakkop Linux - Distributions 3 02-08-2005 07:30 AM
System won't boot properly knoppix doesn't initialize properly rodewan Linux - Software 0 01-23-2005 03:35 PM
Suse 9, RH9 wont install properly. Mandrake 9 wont boot properly? Help. l2ich84 Linux - Newbie 1 01-31-2004 11:02 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:33 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration