Portál AbcLinuxu, 3. prosince 2025 23:57
Řešení dotazu:
Koukni třeba na Getting start programming with Qt, dokonce i tady na Abíčku vycházel seriál o programování s Qt.
connect(tlacitko_QPushButton, SIGNAL(clicked()), text_QLabel, SLOT(hide()));
connect(tlacitko_QPushButton, SIGNAL(clicked()), text_QLabel, SLOT(show()));
No tak v designeru asi na hide nastavit nejde ale do zdrojáku přesně nevím kam to napsat omlouvám se ale jsem prostě jelito :)
#include <QApplication>
#include "widget.h"
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
widget.h
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
class QLabel;
class QPushButton;
class Widget : public QWidget
{
Q_OBJECT
public:
Widget(QWidget *parent = 0);
private:
QLabel* label;
QPushButton* btn;
};
#endif // WIDGET_H
widget.cpp
#include "widget.h"
#include <QtGui>
Widget::Widget(QWidget *parent)
: QWidget(parent)
{
label = new QLabel("ahoj!");
label->hide();
btn = new QPushButton("zobrazit");
btn->setCheckable(true);
QHBoxLayout* layout = new QHBoxLayout(this);
layout->addWidget(btn,5);
layout->addWidget(label);
connect(btn, SIGNAL(clicked(bool)), label, SLOT(setShown(bool)));
// tohle není třeba díky tomu, že při vytváření
// layoutu jsme předali this jako parent
//this->setLayout(layout);
this->setFixedWidth(500);
}
Tiskni
Sdílej:
ISSN 1214-1267, (c) 1999-2007 Stickfish s.r.o.