tags:

views:

19

answers:

1

I used setGeometry() to move and size some buttons and a list on a Window. The problem is that the buttons and list have a certain order and are overlapping strangely. I don't even want them to overlap and don't understand why they are overlapping in the first place.

As they are in the code below, the only thing I can click is BtnPlay. The other button isn't even changing on a mouse over. Depending on how I position them things become click-able.

There was a point where I had the widget created first, furthest to the right, and the widget created last at the origin. Everything worked, which leads me to believe that they are overlapping on an unseen plain, but I don't understand why or how to fix it. In addition, When I put a button near the list (the button was on the left side of the list), for some reason the list was no longer click able. Set geometry allows me to set the top left co-ordinates, the width, and height of the widget. I don't understand why they would interfere with each other.

 int Gui_Init(int argc, char *argv[])
 {
 QApplication app(argc, argv);
 app.setStyle("plastique");
 QWidget Window;
 Window.resize(800, 600);

 QTrackList = new QListObj(&Window);
 RebuildButton BtnRB(&Window);
 PlayButton BtnPlay(&Window);

 Window.show();
 return app.exec();
 return 0;
 }


 RebuildButton::RebuildButton(QWidget *parent) : QWidget(parent)
 {
 Rebuild = new QPushButton(tr("Rebuild Library"), this);
 Rebuild->setGeometry(400,575,100,25);
 connect(Rebuild, SIGNAL(clicked()), this, SLOT(RebuildLibrary()));
 }


 PlayButton::PlayButton(QWidget *parent) : QWidget(parent)
 {
 PlayBtn = new QPushButton(tr("Play Track"), this);
 PlayBtn->setGeometry(400, 550, 100, 25);
 connect(PlayBtn, SIGNAL(clicked()), this, SLOT(PlayTrack()));
 }

The Constructor for QListObj:

 QListObj::QListObj(QWidget *parent) : QWidget(parent)
 {
 List = new QListWidget(parent);
 List->setGeometry(500,0,300,600);
 new QListWidgetItem(tr("fix it"), List);
 connect(List, SIGNAL(itemSelectionChanged()), this, SLOT(SelectTrack()));
 }
+1  A: 

Your design is a bit unconventional, subclassing QWidget to contain a button, but I suspect your problem may be that you are setting the geometry for the buttons relative to the containing QWidget subclasses (RebuildButton and PlayButton) but not setting the geometry for the RebuildButton and PlayButton widgets themselves.

When you feel more comfortable with how things work, you may want to redesign a bit and try to separate your gui from your business logic. Create a subclass of QWidget to act as your application window (or use QMainWindow) and use a combination of layout managers to add/layout all of your gui controls in that subclass constructor.

I would then suggest you make all of your button signal connections to private slots in the window class and from those slots, emit custom signals that trigger business logic to execute elsewhere.

Arnold Spence